how to deal with symbol lookup error? - makefile

a.out call function fooA() using dlopen function to open libA.so.
fooA() is defined in libA.so //dynamic library
fooA() call function fooB();
fooB() is defined in libB.a //statistic library
fooB() call function fooC();
fooC() is defined in libC.so //dynamic library
libA.so libB.a libC.so are not in the same folder.
****
It's ok when i compile them .But i got runtime error which is "symbol lookup error: libA.so: undefined symbol: fooC()" .I dont know why . And how to solve this problem that functions called between dynamic library and statistic library?
I am sorry . My English is poor .I don't know whether i describe my question clearly or not.

Is anything in your binary bringing in libC.so? (directly or through dlopen() with RTLD_GLOBAL)? If not, that's your problem.
libA.so should be built to link to libC (and it was not).

Related

The static library are included, but still link to dynamic library in same name at runtime

I am using nvcodec sdk (https://developer.nvidia.com/nvidia-video-codec-sdk) and use its linux static library in my project.
I added the compile option in gcc with
gcc myprogram.c NvCodec/Lib/linux/stubs/x86_64/libnvcuvid.so
However, when running the program,
./bin/a.out: symbol lookup error: ./bin/a.out: undefined symbol: cuvidGetDecodeStatus
I found that the symbol cuvidGetDecodeStatus is actually in NvCodec/Lib/linux/stubs/x86_64/libnvcuvid.so.
And by
nm a.out
the symbol is included in the program.
so I tried
ldd a.out
I found it's linked to nvidia driver with same name.
libnvcuvid.so.1 => /usr/lib/nvidia-384/libnvcuvid.so.1
I can't modify the LD_LIBRARY_PATH to modify the search order since NvCodec is a static library.
I have no idea why it's linked to the nvidia driver library even I don't add link option (like -lnvcuvid)
And idea?
thank you
as #Robert Crovella said,
this is an issue for an outdated driver. the library in the cuda codec sdk is actually a stub, which points to the cuda driver shared library.
And there is no symbol like cuvidGetDecodeStatus in the nvidia-384 driver library.
after update nvidia-384 to nvidia-396, the problem solved.

Trying to compile OpenVDB

I am trying to compile OpenVDB, but I get a linker error telling me:
"cannot find -ldl"
That is the only linker I am getting. I have no idea what library -ldl belongs to. The makefile doesn't help either, so I'm guessing it is a standard lib. I am using Mingw-w64 on windows.
The -ldl is a linker option to link to libdl library. This library is used to perform dynamic library loading (.dll in Window's world) through dlopen, dlsym... functions.
Since this library is not available on Windows, I think you could remove the -ldl from your makefile.
Since Window's equivatent functions are accessible by kernel.lib, you do not need to add specific instruction in makefile.

Undefined reference to ClockCmd compiling a TK application

I'm trying to compile an example programme using tk. I have nearly all of the libraries sorted, but I think I'm missing one.
Command:
gcc ./tk.c -I/usr/include/tcl8.5/ -ltk8.5 -ltcl8.5 -lm -lpthread -lfontconfig -lX11 -lXft -lXss
Output:
/tmp/cc78MM6w.o: In function `Tk_AppInit':
tk.c:(.text+0xf5): undefined reference to `ClockCmd'
tk.c:(.text+0x120): undefined reference to `ClockObjDestroy'
tk.c:(.text+0x130): undefined reference to `ClockObjCmd'
There's nothing on Google -- anyone recognise ClockCmd? Thanks.
I think those are part of the implementation of Tcl, and should not be referred to outside the Tcl library itself. (The linker is instructed to remove the external reference to them when building the DLL/shared object.) Either that or they are part of your code, and you've simply not supplied them for some reason, but I think you'd know if that was the case.
It would be far easier to work out what's going on if we could actually see the code of tk.c; it's clearly not part of any Tcl or Tk code distribution.
Something wrong with the example code I think; none of the other examples had a problem.

How to link an executable despite missing shared library and associated symbols?

How can I force gcc/ld to go ahead and link a (partially) usable executable despite a missing shared library (and associated missing symbols)?
Context: I have a hardware driver that is distributed only as a 32 bit ELF binary blob (libEposCmd.so). It depends on a library (libftd2xx.so) that I know from context is not actually used (the ftdi stuff is for usb-serial adapters, which I'm not using).
gcc main.o -o epos_server -m32 -L/usr/lib32 -L/usr/local/lib32 -lEposCmd
/usr/bin/ld: warning: libftd2xx.so.0, needed by /usr/local/lib32/libEposCmd.so, not found (try using -rp
ath or -rpath-link)
main.o: In function `main':
/usr/local/lib32/libEposCmd.so: undefined reference to `FT_Write'
/usr/local/lib32/libEposCmd.so: undefined reference to `FT_SetDataCharacteristics'
/usr/local/lib32/libEposCmd.so: undefined reference to `FT_GetDeviceInfoDetail'
/usr/local/lib32/libEposCmd.so: undefined reference to `FT_SetFlowControl'
...
My only undefined references are FT_*, which I am fairly certain all belong to libftd2xx.
Ugly hacks are acceptable; this is research code and we hope to replace this hardware (maxon epos2 motor driver) with something with better linux support ASAP.
Update: The .so is ~not stripped, so it should be possible to extract prototypes for the missing functions...
The quickest way is to create a dummy lib with the missing functions and link with it.

gcc undefined _cxa_pure_virtual

I have 2 shared object libs and one executable.
1 of the libs that I compile has linkage error: Undefined _cxa_pure_virtual.
Why?
Usually we do not need to implement it. Any Ideas?
If I implement it both the libs compile and link OK, but the application that links to both has same linkage issue?
The lib in question is a C++ library and the __cxa_pure_virtual is needed by the C++ runtime. Suggest that you try first linking with g++ command instead of gcc.
Read more under this question: What is the purpose of cxa pure virtual

Resources