[英]DLL linking failed with LTO using MinGW-W64
I failed to build a shared library for Windows x86-64 using MinGW-W64 with -flto
. 我无法使用MinGW-W64和-flto
为Windows x86-64构建共享库。 Here is what I get (compilation is done on a Linux box): 这是我得到的(编译在Linux机器上完成):
# ...
x86_64-w64-mingw32-g++ -c -std=gnu++11 -fvisibility=hidden -DGLEW_STATIC -Ofast -flto -frtti -pedantic -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -I'include' -I'/usr/x86_64-w64-mingw32/share/qt4/mkspecs/win32-g++-cross-x64' -o build/Point3D.o src/Point3D.cpp
x86_64-w64-mingw32-g++ -mwindows -Ofast -flto -shared -Wl,-subsystem,windows -mthreads -Wl,--out-implib,lib/libglengine.a -o lib/glengine.dll object_script.glengine.Release -lopengl32 -Wl,-Bstatic -lturbojpeg -lpng -lwebpdecoder
Cannot export _ZNSt6vectorI6StringSaIS0_EE19_M_emplace_back_auxIJRKS0_EEEvDpOT_: symbol wrong type (4 vs 3)
Cannot export _ZNSt6vectorIPN3GLE6ShaderESaIS2_EE19_M_emplace_back_auxIJRKS2_EEEvDpOT_: symbol wrong type (4 vs 3)
Cannot export _ZNSt6vectorIPN3GLE7ProgramESaIS2_EE19_M_emplace_back_auxIJRKS2_EEEvDpOT_: symbol wrong type (4 vs 3)
collect2: error: ld returned 1 exit status
Makefile.Release:211: recipe for target 'lib/glengine.dll' failed
Compiles fine for Linux with and without LTO, and for Windows without LTO. 使用和不使用LTO以及没有LTO的Windows编译适用于Linux。
These symbols refer to: 这些符号指的是:
void std::vector<String, std::allocator<String> >::_M_emplace_back_aux<String const&>(String const&)
void std::vector<GLE::Shader*, std::allocator<GLE::Shader*> >::_M_emplace_back_aux<GLE::Shader* const&>(GLE::Shader* const&)
void std::vector<GLE::Program*, std::allocator<GLE::Program*> >::_M_emplace_back_aux<GLE::Program* const&>(GLE::Program* const&)
That is, each time I use a std::vector
. 也就是说,每次我使用std::vector
。
I ran into the same problem. 我遇到了同样的问题。
What helped for me is to add -fno-use-linker-plugin
to the linker flags. 对我有帮助的是将-fno-use-linker-plugin
到链接器标志。
-fno-use-linker-plugin
causes the lto optimizations to be done in gcc rather than the linker + the gcc linker plugin. -fno-use-linker-plugin
导致lto优化在gcc而不是链接器+ gcc链接器插件中完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.