简体   繁体   中英

DLL linking failed with LTO using MinGW-W64

I failed to build a shared library for Windows x86-64 using MinGW-W64 with -flto . Here is what I get (compilation is done on a Linux box):

# ...
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.

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 .

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 causes the lto optimizations to be done in gcc rather than the linker + the gcc linker plugin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM