GCC -rdynamic not working with static libraries

前端 未结 2 2009
天命终不由人
天命终不由人 2020-12-17 04:03

Why is -rdynamic not exporting the symbols in .a files but is exporting the symbols in .o files ?

I have an app and a plug-in in a .so file. The main app is linked u

相关标签:
2条回答
  • 2020-12-17 04:26

    A .o file is ELF relocatable, and, a .so file is ELF shared object. Whereas a .a file is current archive. When the linker is passed the --export-dynamic flag through the -rdynamic from gcc, it is looking for a dynamic object file.

    I think the linker does not care to look into the archive and extract the symbols.

    0 讨论(0)
  • 2020-12-17 04:48

    Normally, the linker only includes those parts of static archives (.a files) which are referenced.

    To force the linker to include the entire contents of a .a file, you can use the --whole-archive linker option (so -Wl,--whole-archive on the gcc command line).

    Note that -Wl,--whole-archive is position-sensitive on the command line — it only affects .a files following it on the command line. Its effect may be subsequently turned off using -Wl,--no-whole-archive, if there are further static archives which you don't want to be completely included.

    So, for instance, with your command:

    $(CXX) $(CXXFLAGS) -o $(SAMPLE) main.o -Wl,--whole-archive $(STATICLIBS) -Wl,--no-whole-archive $(SHAREDLIBS) $(INCLUDES)
    
    0 讨论(0)
提交回复
热议问题