g++ cannot link to libdl even with -ldl flag

2019-07-26 16:32发布

问题:

I am attempting to compile an example application for a USB camera (mvBlueFOX) sold by Matrix Vision. They provide me with the source code for the application, a make file, and a set of pre-compiled shared libraries. However, the make file fails to successfully build an executable. A "make" returns:

carter@carter-Lenovo-G780:~/mvimpact_acquire-x86-1.12.22.254/apps/LiveSnap$ make
make[1]: Entering directory `/home/carter/mvimpact_acquire-x86-1.12.22.254/apps/LiveSnap/x86'
/usr/bin/g++     -O2 -Wall -W -fPIC -D_REENTRANT -D_GNU_SOURCE -D_MAJOR_VERSION=1 -D_MINOR_VERSION=12 -D_BUILD_VERSION=22 -D_BUILD2_VERSION=254  -DMALLOC_TRACE -DNDEBUG      -I../../..   -o LiveSnap LiveSnap.o     -L../../../lib/x86 -lmvDeviceManager -lmvPropHandling    -lm -lpthread   -ldl 
../../../lib/x86/libmvPropHandling.so: undefined reference to `dlsym'
../../../lib/x86/libmvPropHandling.so: undefined reference to `dlopen'
../../../lib/x86/libmvPropHandling.so: undefined reference to `dlclose'
collect2: ld returned 1 exit status
make[1]: *** [LiveSnap] Error 1
make[1]: Leaving directory `/home/carter/mvimpact_acquire-x86-1.12.22.254/apps/LiveSnap/x86'
make: *** [all] Error 2

A simplified version of the link command:

g++ -o LiveSnap x86/LiveSnap.o -lmvDeviceManager -ldl

Still returns:

../../../lib/x86/libmvPropHandling.so: undefined reference to `dlsym'
../../../lib/x86/libmvPropHandling.so: undefined reference to `dlopen'
../../../lib/x86/libmvPropHandling.so: undefined reference to `dlclose'

libdl.so is being found, however the process still fails. Is this an issue with my version of libdl or is there another problem?

回答1:

If your gcc version is above 4.6.2 just add the flag '-Wl,--no-as-needed' before -lmvDeviceManager



回答2:

For those interested in a work around to this problem, I was able to successfully build and run a newer version of the code that I downloaded from the Movie-Matrix website. The version provided on the CD with my camera was 1.2.22 while the version from the website was 2.5.2. Why the older version fails to build is still unknown, but the problem seems to be solved in newer versions of the software.



标签: c++ linker g++