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

Undefined reference __imp__ZN3fmt2v58internal10basic_dataIvE6DIGITSE when using DLL on MinGW #1204

Closed
HazardyKnusperkeks opened this issue Jun 23, 2019 · 8 comments

Comments

@HazardyKnusperkeks
Copy link
Contributor

Hi,

I'm using MinGW 8.1 to build fmt as dll and then using it. I'm defining FMT_EXPORT for building of the dll, and FMT_SHARED for the using projects.
I have updated my copy and now I'm getting

<file>:(.text+0x147): undefined reference to `__imp__ZN3fmt2v58internal10basic_dataIvE6DIGITSE'

etc., I think this is related to the commit 29c10fb

My fix is just # define FMT_EXTERN_TEMPLATE_API FMT_API in any case.
Also I'm getting a warning

\fmt\src\format.cc:11: Warnung: type attributes ignored after type is already defined [-Wattributes]
template struct FMT_API internal::basic_data;
^~~~~~~~~~~~~~~~

which disappears if I remove FMT_API in the .cc.

@HazardyKnusperkeks
Copy link
Contributor Author

The above only makes it compile and link. But I get a crash at runtime (not even debuggable), for now I have additionally removed the extern template instantiation for void.

@vitaut
Copy link
Contributor

vitaut commented Jun 26, 2019

I don't have a Windows machine at hand to debug this, but a PR is welcome. You could also use a static library which is the default and recommended build configuration.

@vedranmiletic
Copy link

@vitaut if you have a Linux machine, you can use the MinGW cross-compiler which exhibits the same issue (both 32-bit and 64-bit).

Static build indeed works fine.

@bbolli
Copy link
Contributor

bbolli commented Aug 26, 2019

@vitaut:

You could also use a static library which is the default and recommended build configuration.

Should packages (like the mingw one) build the shared library at all? Or just the static one to push users to the recommended usage?

@luncliff
Copy link
Contributor

luncliff commented Aug 28, 2019

@HazardyKnusperkeks have you tried the CMake's symbol exporting?
This exports all symbols in .dll to .lib. In short, it works like __attribute__((visibility("default"))).

set_target_properties(fmt
PROPERTIES
    WINDOWS_EXPORT_ALL_SYMBOLS  true
)

I'm not sure it will work for MinGW, but it did for my 'clang-cl' related works.

@vitaut
Copy link
Contributor

vitaut commented Aug 28, 2019

Should packages (like the mingw one) build the shared library at all? Or just the static one to push users to the recommended usage?

The current default is already the static library but some systems have their own policies which may require building shared libraries.

bbolli added a commit to bbolli/fmt that referenced this issue Aug 28, 2019
@HazardyKnusperkeks
Copy link
Contributor Author

@HazardyKnusperkeks have you tried the CMake's symbol exporting?
This exports all symbols in .dll to .lib. In short, it works like __attribute__((visibility("default"))).

set_target_properties(fmt
PROPERTIES
    WINDOWS_EXPORT_ALL_SYMBOLS  true
)

I'm not sure it will work for MinGW, but it did for my 'clang-cl' related works.

I've not tried anything apart from what I mentioned in the opening. Because I currently have not much time for my private coding and in the company code we don't use fmt yet.

Apart from that I don't use CMake at all.

bbolli added a commit to bbolli/fmt that referenced this issue Sep 2, 2019
@vitaut
Copy link
Contributor

vitaut commented Nov 17, 2019

Looks like a GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50044. A possible workaround is to define FMT_EXTERN_TEMPLATE_API to FMT_API on MinGW or use a static library. Closing as this is not a bug in {fmt} but would be happy to accept a PR to workaround the issue.

@vitaut vitaut closed this as completed Nov 17, 2019
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

5 participants