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

Linking shared libraries with dependencies

$
0
0

I have a program which is dependent upon a library (called "libFoo.so" here). libFoo.so is also dependent upon a number of other libraries: libVendor.so, libFooVendor.so, and liblog.so. Whenever I try to link against just libFoo.so, ie arm-linux-gnueabi-gcc -o myprogram main.c -lFoo, and run the program, I get "undefined symbol: main".

However, if I link in the other libraries via arm-linux-gnueabi-gcc -o myprogram main.c -lFoo -lFooVendor -lVendor -llog everything works.

I know this isn't the "right" way to handle a library that is dependent on other libraries. I should be using rpath or rpath-link. All of the libraries for my program are in /usr/lib/. When I try to use rpath=/usr/lib or rpath-link=[path to my libraries in my cross compilation chain], it doesn't seem to affect the result. I still get "undefined symbol: main"

How can I resolve this? Should I be creating libFoo.so differently? It's made with (header includes and shared library paths removed) arm-linux-gnueabi-gcc -o libFoo.so -shared -fPIC source.c -lFooVendor -lVendor -llog

Example: libFoo.so

arm-linux-gnueabi-readelf -d out/libFoo.so Dynamic section at offset 0x7e1a8 contains 33 entries:  Tag        Type                         Name/Value 0x00000003 (PLTGOT)                     0x7f738 0x00000002 (PLTRELSZ)                   13400 (bytes) 0x00000017 (JMPREL)                     0x3bc18 0x00000014 (PLTREL)                     REL 0x00000011 (REL)                        0x3b420 0x00000012 (RELSZ)                      2040 (bytes) 0x00000013 (RELENT)                     8 (bytes) 0x6ffffffa (RELCOUNT)                   27 0x00000006 (SYMTAB)                     0x158 0x0000000b (SYMENT)                     16 (bytes) 0x00000005 (STRTAB)                     0x94b8 0x0000000a (STRSZ)                      180325 (bytes) 0x00000001 (NEEDED)                     Shared library: [libFooVendor.so.0] 0x00000001 (NEEDED)                     Shared library: [libVendor.so.0] 0x00000001 (NEEDED)                     Shared library: [liblog.so.0] 0x00000001 (NEEDED)                     Shared library: [libstdc++.so.6] 0x00000001 (NEEDED)                     Shared library: [libm.so.6] 0x00000001 (NEEDED)                     Shared library: [libgcc_s.so.1] 0x00000001 (NEEDED)                     Shared library: [libc.so.6] 0x0000000c (INIT)                       0x3f070 0x0000000d (FINI)                       0x76504 0x00000019 (INIT_ARRAY)                 0x7f334 0x0000001b (INIT_ARRAYSZ)               28 (bytes) 0x0000001a (FINI_ARRAY)                 0x7f350 0x0000001c (FINI_ARRAYSZ)               4 (bytes) 0x6ffffff0 (VERSYM)                     0x3a0e8 0x6ffffffc (VERDEF)                     0x3b354 0x6ffffffd (VERDEFNUM)                  1 0x6ffffffe (VERNEED)                    0x3b370 0x6fffffff (VERNEEDNUM)                 3 0x00000000 (NULL)                       0x0

Example: program linked only with -lFoo

arm-linux-gnueabi-readelf -d out/myprogram Dynamic section at offset 0xc5c contains 27 entries:  Tag        Type                         Name/Value 0x00000003 (PLTGOT)                     0x9d74 0x00000002 (PLTRELSZ)                   128 (bytes) 0x00000017 (JMPREL)                     0x855c 0x00000014 (PLTREL)                     REL 0x00000011 (REL)                        0x8554 0x00000012 (RELSZ)                      8 (bytes) 0x00000013 (RELENT)                     8 (bytes) 0x00000015 (DEBUG)                      0x0 0x00000006 (SYMTAB)                     0x81ac 0x0000000b (SYMENT)                     16 (bytes) 0x00000005 (STRTAB)                     0x833c 0x0000000a (STRSZ)                      398 (bytes) 0x6ffffef5 (GNU_HASH)                   0x84cc 0x00000001 (NEEDED)                     Shared library: [libFoo.so] 0x00000001 (NEEDED)                     Shared library: [libc.so.6] 0x0000000c (INIT)                       0x85dc 0x0000000d (FINI)                       0x8c14 0x00000019 (INIT_ARRAY)                 0x9d64 0x0000001b (INIT_ARRAYSZ)               4 (bytes) 0x0000001a (FINI_ARRAY)                 0x9d68 0x0000001c (FINI_ARRAYSZ)               4 (bytes) 0x6ffffff0 (VERSYM)                     0x8500 0x6ffffffe (VERNEED)                    0x8534 0x6fffffff (VERNEEDNUM)                 1 0x00000000 (NULL)                       0x0

Viewing all articles
Browse latest Browse all 22162

Trending Articles



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