当从一堆用标志编译的目标文件中组合一个共享库时,我试图让gcc's忽略未解析的引用。ld-fpic
到目前为止,我尝试了很多选项,例如(为简洁起见,将许多目标文件的长文件名替换为一些小文件名):
ld --allow-shlib-undefined --unresolved-symbols=ignore-all -shared 1.o 2.o -o lib0.so
ld -G 1.o 2.o -o lib0.so
(我有红色的地方允许-G未解决的引用,但没有运气。)
运行它gcc(with -Wl,--unresolved-symbols=ignore-all)会减少未解析的引用,因为它默认链接为
-lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -liconv -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt
但它仍然抱怨没有-lopengl32and -lgdi32。
在没有 的情况下编译库-fpic,将所有目标文件存储在一个.awithar和静态链接中,同时让 exe 程序链接到它-lopengl32并-lgdi32导致工作完全正常。
实际的错误消息(为简洁起见,替换了长文件和函数名):
[file].o: In function `[function]': [file].cpp:19: undefined reference to `memcpy'
[file].o: In function `[function]': [file].cpp:26: undefined reference to `memcpy'
[file].o:[file].cpp:(.xdata+0x4c): undefined reference to `__gxx_personality_seh0'
[file].o:[file].cpp:(.xdata+0x74): undefined reference to `__gxx_personality_seh0'
[file].o:[file].cpp:(.rdata$[file]]+0x20):undefined reference to `__cxa_pure_virtual'
[file].o:[file].cpp:(.rdata$[file]]+0x28): undefined reference to `__cxa_pure_virtual'
我怎样才能ld忽略未定义的引用(至少来自libopengl32和libgdi32如果不是libstdc++等)并让将要使用它的程序链接到它们?