Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Duplicate templates using MSYS2 GNU C++ compiler #7

Open
corradomio opened this issue Jul 21, 2023 · 0 comments
Open

[BUG] Duplicate templates using MSYS2 GNU C++ compiler #7

corradomio opened this issue Jul 21, 2023 · 0 comments

Comments

@corradomio
Copy link

corradomio commented Jul 21, 2023

It is possible to compile the library using MSYS2 GNU C++.
However there is a problem on how GNU C++ and Microsoft CL handle the template instantiation.

The problem is located in WSTP .h/.c. files, in the template definitions as (for example in Get.h)

template<>
	GetArray<unsigned char>::Func GetArray<unsigned char>::ArrayF = WSGetInteger8Array;

MSYS2 GNU C++ define the macro "_WIN32". This means that in "Get.c/Get.h" is active the "else" part of

#ifndef _WIN32
...
#else

	template<>
	GetArray<unsigned char>::Func GetArray<unsigned char>::ArrayF = WSGetInteger8Array;
        ...
#endif

When GNU C++ compiler includes the .h in ANOTHER project, it instantiate the template.
BUT the template is ALREADY instantiated and present in "libLLU.a", the library created compiling these source files.
This generates a linker error for "multiple instances of the same template".

The solution can be simple: it is enough to replace

#ifndef _WIN32

with

#if !defined(_WIN32) || defined(__GNUC__)

where GNUC is a unique predefined macro in GNU C/C++ compiler, in this way, the templates are instantiates inside *.c and made them available as "extern template" in the other projects.

@corradomio corradomio changed the title [ENH] Duplicate templates using MSYS2 GNU g++ compiler [ENH] Duplicate templates using MSYS2 GNU C++ compiler Jul 21, 2023
@corradomio corradomio changed the title [ENH] Duplicate templates using MSYS2 GNU C++ compiler [BUG] Duplicate templates using MSYS2 GNU C++ compiler Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant