1

There are no symbols of static library files or functins in a dynamic library(.so) file.

I am using ubuntu 18.04 and 12.04 system. I created an object file from cpp file with -fPIC option than the created static library (.a). After that I created a dynamic library using a command :g++ -shared -I(include path) -L(other library path) -l(librarys) -o filename.so -Wl,-soname,filename.so staticlib.a" I show symbol created in 12.04 ubuntu system but not in 18.04 system. I show so file created by there no symbols in so file. we can check it using nm -g filename .so.

I got this type of result in nm command in 18.04 system if I try with 12.04 it give me whole sysmbols of all cpp files.

$ nm -g libPJ.so
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
0000000000201020 B __bss_start
                 w __cxa_finalize
                 w __gmon_start__
0000000000201020 D _edata
0000000000201028 B _end
000000000000052c T _fini
0000000000000410 T _init
  • 1
    Possible duplicate: [Keep all exported symbols when creating a shared library from a static library](https://stackoverflow.com/questions/54664759/keep-all-exported-symbols-when-creating-a-shared-library-from-a-static-library) – MofX Aug 09 '19 at 11:33
  • I suspect you are using gcc, please add it to the tags, since this is no general c question – MofX Aug 09 '19 at 11:34
  • @Raidri thank this link works for me. I need to use -Wl,--whole-archive and -Wl,--no-whole-archive before and after static lib. – chaitanya sonagara Aug 10 '19 at 03:54

1 Answers1

0

When linking a shared library from a static library add -Wl,-whole-archive linker flag. From man ld:

  --whole-archive
       For each archive mentioned on the command line after the
       --whole-archive option, include every object file in the archive in
       the link, rather than searching the archive for the required object
       files.  This is normally used to turn an archive file into a shared
       library, forcing every object to be included in the resulting
       shared library.  This option may be used more than once.

     Two notes when using this option from gcc: First, gcc doesn’t know
       about this option, so you have to use -Wl,-whole-archive.  Second,
       don’t forget to use -Wl,-no-whole-archive after your list of
       archives, because gcc will add its own list of archives to your
       link and you may not want this flag to affect those as well.
Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271