0

The scenario(Linux):

   Executable -> shared library -> [xrt static library]
                                   (It is a commercial product based on Motif)

The executable will call the shared library, and the shared library will call static library.

I do the following to compile and linking the shared library:

$ gcc -fPIC --unresolved-symbols=ignore-in-shared-lib -c demo.c      (compling)
$ gcc -shared -o libdemo.so demo.o                                   (linking)

Note here, I do not link the xrt static library though it uses the xrt static library functions

The executable will link the shared library(libdemo.so) like below:

$ gcc -fPIC --unresolved-symbols=ignore-in-shared-lib main.c -Ixxxx
$ gcc -o main main.o -Lxxxx -ldemo -L/opt/xrt/lib -lxrtm -lXpm -lxrt3d -lxrtfield -lxrtgauge -lxrtm -lxrttable -lpdsutil

Here the executable linked the xrt static library

When I run the executable it gives me 'symbol lookup error':

$ ./main
./main: symbol lookup error: /xxx/libdemo.so: undefined symbol: xmXrtTabManagerWidgetClass

In the xrt static library directory, it has some static libraries. And when I run nm command, it gives me the below result:

$ nm *.a | grep xmXrtTabManagerWidgetClass
                  U xmXrtTabManagerWidgetClass
0000000000000b18  D xmXrtTabManagerWidgetClass
                  U xmXrtTabManagerWidgetClass
                  U xmXrtTabManagerWidgetClass

The xmXrtTabManagerWidgetClass symbol is defined in commercial product (which wrapped in static library). Is there any way to solve this problem?

  • What does `ldd main` output? – kiner_shah Mar 14 '23 at 11:19
  • `ldd main` gives me : libdemo.so (0x.....) and some other stuff. Because the xrt static library is linked into the `main`, they are not shown on the result. – HuangHaiFeng Mar 15 '23 at 00:23
  • Makes sense. By any chance do you know if your static library was built using `-fPIC` option? Have a look at this answer, may help: https://stackoverflow.com/a/41858529/4688321 – kiner_shah Mar 15 '23 at 06:22
  • I've confirmed that the static library was not built using the `-fPIC` option. Is it a must? – HuangHaiFeng Mar 15 '23 at 06:50
  • Not sure really, maybe you can read more about this. I am sure many people have already tried this before. – kiner_shah Mar 15 '23 at 06:51
  • Have a look at this answer, it seems you need `-fPIC`: https://stackoverflow.com/a/53086721/4688321 – kiner_shah Mar 15 '23 at 06:54
  • 1
    Yes, actually it must be linked with `-fPIC`, or else the app will encounter many `symbol lookup error`. Thanks a lot for your help. – HuangHaiFeng Mar 16 '23 at 02:15

0 Answers0