Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22016

getting ld to ignore undefined references when making a shared lib

$
0
0

I'm trying to get gcc's ld to ignore unresolved references when putting together a shared library from a bunch of object files compiled with -fpic flag.

I tried a bunch of options so far such as (replaced the long file names of the many object files with a few small ones for brevity):

ld --allow-shlib-undefined --unresolved-symbols=ignore-all -shared 1.o 2.o -o lib0.sold -G 1.o 2.o -o lib0.so

(I've red somewhere that -G will allow unresolved references, but had no luck with it.)

Running it though gcc (with -Wl,--unresolved-symbols=ignore-all) results in fewer unresolved references as it links by default with

-lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -liconv -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt

but it still complains about not having -lopengl32 and -lgdi32.

Compiling the lib without -fpic, stashing all the object files in a .a with ar and static linking to it while having the exe program link to -lopengl32 and -lgdi32 results in working completely fine.

The actual error messages (replaced the long file and function names for brevity):

[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'

How can I get ld to ignore undefined references (at least from libopengl32 and libgdi32 if not libstdc++ etc too) and let the program thats going to use it link to them?


Viewing all articles
Browse latest Browse all 22016

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>