collect2.exe: error: ld returned 5 exit status

十年热恋 提交于 2021-02-04 22:17:31

问题


I've recently updated all msys2 packages and now I can't build my project. The error occurs at the moment of linking one of .dlls - target_library.dll.

The error message isn't clear to me. What does status 5 mean?

collect2.exe: error: ld returned 5 exit status

Full message:

g++ -Wl,-s,--relax,--gc-sections -shared -Wl,-subsystem,windows -mthreads -Wl,--out-implib,C:/msys64/workspace/Project_Root_Directory/project/src/../build/release/plugins/libtarget_library.dll.a -o ../../../../build/release/plugins/target_library.dll object_script.target_library.Release  -lglu32 -lopengl32 -luser32 -LC:/msys64/workspace/Project_Root_Directory/project/build/release -LC:/msys64/workspace/Project_Root_Directory/project/third-party/out/lib -LC:/msys64/workspace/Project_Root_Directory/project/deps/lib -lexif -ldecimal -lsqlite3 -lutils -LC:/Python35/libs -lpython35 -lkmlbase -lkmlengine -lkmldom -lkmlxsd -lminizip -luriparser -lkmlconvenience -lcore -lrender -lraster -lgui -LC:/msys64/workspace/Project_Root_Directory/project/deps/lib/target_library/win64 -LC:/msys64/mingw64/lib  C:/msys64/mingw64/lib/libQt5Widgets.dll.a C:/msys64/mingw64/lib/libQt5WinExtras.dll.a C:/msys64/mingw64/lib/libQt5Gui.dll.a C:/msys64/mingw64/lib/libQt5Network.dll.a C:/msys64/mingw64/lib/libQt5Concurrent.dll.a C:/msys64/mingw64/lib/libQt5Xml.dll.a C:/msys64/mingw64/lib/libQt5Core.dll.a

collect2.exe: error: ld returned 5 exit status
make[4]: *** [Makefile.Release:159: ../../../../build/release/plugins/target_library.dll] Error 1
make[4]: Leaving directory '/workspace/Project_Root_Directory/project/src/modules/plugins/target_library'
make[3]: Leaving directory '/workspace/Project_Root_Directory/project/src/modules/plugins/target_library'
make[2]: *** [Makefile:384: sub-target_library-make_first] Error 2
make[2]: Leaving directory '/workspace/Project_Root_Directory/project/src/modules/plugins'
make[1]: *** [Makefile:297: sub-plugins-make_first] Error 2
make[1]: Leaving directory '/workspace/Project_Root_Directory/project/src/modules'
make: *** [Makefile:44: sub-modules-make_first] Error 2

gcc 7.1.0, Qt5 5.9.1, qmake, Win7 x64


回答1:


I had the same issue. I link my project with static library. After mingw64 upgrade, my project stoped building with the same error. I found out that debug version built successfully. So i compared linker flags. In release version Qt add this flags "-Wl,-s,--relax,--gc-section". I couldn't find any information about "-s" flag, but due to this link i figured out that -gc-section flag was the reason of fail. I added the following code to my .pro-file, and it worked

mingw {
        contains(QT_ARCH, x86_64): {
            LIBS+=-Wl,--no-gc-sections
        }
}



回答2:


Just in case someone finds this due the same problem, please, add the following flag to your compiler -Wl,--verbose (or --verbose to the linker). This will show which library was not found or give you more information about the problem.



来源:https://stackoverflow.com/questions/45077846/collect2-exe-error-ld-returned-5-exit-status

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!