[CMake] Linker Path Issues: /usr/local/lib
Michael Hertling
mhertling at online.de
Thu Jul 14 22:19:06 EDT 2011
On 07/14/2011 07:19 PM, Ryan Farrell wrote:
> Hi everyone,
>
> I'm using cmake to try and Build the latest release of OpenCV (2.3), but
> am encountering an error. It's important to know that this is on a
> shared cluster machine where I don't have root access. I've therefore
> built and installed a few libraries (ffmpeg for example) locally. I'm
> trying to use these libraries (which, unlike the system installed
> versions, have both static and shared libraries built) in my opencv
> build. Somehow /usr/local/lib is creeping into my build and causing
> problems... I haven't specified that path anywhere and it's not in my
> PATH/LD_LIBRARY_PATH environment variables:
>
> PATH=[trimmed]/farrell/bin:/u/vis/software/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11/bin
> LD_LIBRARY_PATH=/u/vis/software/lib:/usr/lib64:/usr/lib
>
>
>
> So, here's the command that I'm using to configure with cmake and the
> output it produces (trimmed in a few places for brevity). Cmake seems
> to find the ffmpeg libraries fine (in particular, libavcodec which is
> the one it dies on when building). Note that /usr/local/lib is also
> producing some troublesome warnings about hiding the correct libraries
> in /usr/lib64...
>
>
> farrell at banana2:/u/vis/software/dist/OpenCV-2.3.0/release> cmake
> -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_PYTHON_SUPPORT=1
> -DCMAKE_INSTALL_PREFIX=/u/vis/software -DCMAKE_VERBOSE=1
> -DCMAKE_BUILD_WITH_INSTALL_RPATH=1 ..
> -- The C compiler identification is GNU
> -- The CXX compiler identification is GNU
> -- Check for working C compiler: /usr/bin/gcc
> -- Check for working C compiler: /usr/bin/gcc -- works
> -- Detecting C compiler ABI info
> -- Detecting C compiler ABI info - done
> -- Check for working CXX compiler: /usr/bin/c++
> -- Check for working CXX compiler: /usr/bin/c++ -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Extracting svn version, please wait...
> -- SVNVERSION:
> -- Detected version of GNU GCC: 41 (401)
>
> ...
>
> -- package 'gstreamer-video-0.10' not found
> *-- checking for module 'libavcodec'
> -- found libavcodec, version 52.20.0
> *-- checking for module 'libavformat'
> -- found libavformat, version 52.31.0
> -- checking for module 'libavutil'
> -- found libavutil, version 49.15.0
> -- checking for module 'libswscale'
> -- found libswscale, version 0.7.1
> -- Looking for libavformat/avformat.h
> -- Looking for libavformat/avformat.h - found
> -- Looking for ffmpeg/avformat.h
> -- Looking for ffmpeg/avformat.h - not found
> -- checking for module 'libdc1394-2'
>
> ...
>
> -- Parsing 'cvconfig.h.cmake'
> -- GRFMT:
> /usr/lib64/libz.so;/usr/lib64/libjpeg.so;/usr/lib64/libpng.so;/usr/lib64/libz.so;/usr/lib64/libtiff.so;libjasper
> -- HIGHGUI_LIBS:
> gthread-2.0;rt;glib-2.0;avcodec;avformat;avutil;swscale;/usr/lib64/libbz2.so
> -- OPENCV_LIBS: dl;m;pthread;rt
> --
> -- General configuration for opencv 2.3.0
> =====================================
> --
> -- Built as dynamic libs?: ON
> -- Compiler:
> -- C++ flags (Release): -Wall -Wno-long-long -pthread
> -ffunction-sections -O3 -DNDEBUG -fomit-frame-pointer -ffast-math
> -msse -msse2 -DNDEBUG
> -- C++ flags (Debug): -Wall -Wno-long-long -pthread
> -ffunction-sections -g -O0 -DDEBUG -D_DEBUG -ggdb3
> -- Linker flags (Release):
> -- Linker flags (Debug):
> --
>
> ...
>
> --
> -- Video I/O:
> -- DC1394 1.x: 0
> -- DC1394 2.x: 0
> *-- FFMPEG: 1
> -- codec: 1
> *-- format: 1
> -- util: 1
> -- swscale: 1
> -- gentoo-style: 1
> -- GStreamer: 0
> -- UniCap: FALSE
> -- PvAPI:
> -- V4L/V4L2: /
> -- Xine: FALSE
> --
>
> ...
>
> -- Documentation:
> -- Build Documentation: NO
> --
> -- Install path: /u/vis/software
> --
> -- cvconfig.h is in: /u/vis/software/dist/OpenCV-2.3.0/release
> -- -----------------------------------------------------------------
> --
> -- Configuring done
> CMake Warning at modules/highgui/CMakeLists.txt:259 (add_library):
> Cannot generate a safe linker search path for target opencv_highgui
> because
> files in some directories may conflict with libraries in implicit
> directories:
>
> link library [libz.so] in */usr/lib64* may be hidden by files in:
> */usr/local/lib
> * link library [libtiff.so] in */usr/lib64* may be hidden by files in:
> */usr/local/lib
>
> * Some of these libraries may not be found correctly.
>
>
> CMake Warning at modules/highgui/CMakeLists.txt:259 (add_library):
> Cannot generate a safe runtime search path for target opencv_highgui
> because files in some directories may conflict with libraries in implicit
> directories:
>
> runtime library [libz.so.1] in /usr/lib64 may be hidden by files in:
> /usr/local/lib
> runtime library [libtiff.so.3] in /usr/lib64 may be hidden by files in:
> /usr/local/lib
>
> Some of these libraries may not be found correctly.
>
>
> CMake Warning at modules/highgui/CMakeLists.txt:399 (add_executable):
> Cannot generate a safe linker search path for target opencv_test_highgui
> because files in some directories may conflict with libraries in implicit
> directories:
>
> link library [libz.so] in /usr/lib64 may be hidden by files in:
> /usr/local/lib
>
> Some of these libraries may not be found correctly.
>
>
> CMake Warning at modules/highgui/CMakeLists.txt:399 (add_executable):
> Cannot generate a safe runtime search path for target opencv_test_highgui
> because files in some directories may conflict with libraries in implicit
> directories:
>
> runtime library [libz.so.1] in /usr/lib64 may be hidden by files in:
> /usr/local/lib
>
> Some of these libraries may not be found correctly.
>
>
> -- Generating done
> CMake Warning:
> Manually-specified variables were not used by the project:
>
> BUILD_PYTHON_SUPPORT
>
>
> -- Build files have been written to:
> /u/vis/software/dist/OpenCV-2.3.0/release
>
>
>
>
> Then, when I run the build, I get the error below, showing that the
> "-L/usr/local/lib" is causing the problem, clearly taking precedence
> over the rpath "-Wl,-rpath,/u/vis/software/lib:/usr/local/lib".
>
>
>
> Linking CXX shared library ../../lib/libopencv_highgui.so
> /usr/bin/c++ -fPIC -Wall -Wno-long-long -pthread -ffunction-sections
> -O3 -DNDEBUG -fomit-frame-pointer -ffast-math -msse -msse2 -DNDEBUG
> -shared -Wl,-soname,libopencv_highgui.so.2.3 -o
> ../../lib/libopencv_highgui.so.2.3.0
> CMakeFiles/opencv_highgui.dir/src/cap.o
> CMakeFiles/opencv_highgui.dir/src/cap_images.o
> CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o
> CMakeFiles/opencv_highgui.dir/src/loadsave.o
> CMakeFiles/opencv_highgui.dir/src/precomp.o
> CMakeFiles/opencv_highgui.dir/src/utils.o
> CMakeFiles/opencv_highgui.dir/src/window.o
> CMakeFiles/opencv_highgui.dir/src/bitstrm.o
> CMakeFiles/opencv_highgui.dir/src/grfmt_exr.o
> CMakeFiles/opencv_highgui.dir/src/grfmt_tiff.o
> CMakeFiles/opencv_highgui.dir/src/grfmt_jpeg2000.o
> CMakeFiles/opencv_highgui.dir/src/grfmt_bmp.o
> CMakeFiles/opencv_highgui.dir/src/grfmt_imageio.o
> CMakeFiles/opencv_highgui.dir/src/grfmt_png.o
> CMakeFiles/opencv_highgui.dir/src/grfmt_sunras.o
> CMakeFiles/opencv_highgui.dir/src/grfmt_base.o
> CMakeFiles/opencv_highgui.dir/src/grfmt_pxm.o
> CMakeFiles/opencv_highgui.dir/src/grfmt_jpeg.o *-L/usr/local/lib* -ldl
> -lm -lpthread -lrt ../../lib/libopencv_core.so.2.3.0
> ../../lib/libopencv_imgproc.so.2.3.0 -lz -ljpeg -lpng -lz -ltiff
> ../../3rdparty/lib/liblibjasper.a -lgthread-2.0 -lrt -lglib-2.0
> -lavcodec -lavformat -lavutil -lswscale -lbz2
> ../../lib/libopencv_core.so.2.3.0 -ldl -lm -lpthread -lz -lrt
> *-Wl,-rpath,/u/vis/software/lib:/usr/local/lib *
> /usr/bin/ld: skipping incompatible /usr/local/lib/libz.so when searching
> for -lz
> /usr/bin/ld: skipping incompatible /usr/local/lib/libz.a when searching
> for -lz
> /usr/bin/ld: skipping incompatible /usr/local/lib/libz.so when searching
> for -lz
> /usr/bin/ld: skipping incompatible /usr/local/lib/libz.a when searching
> for -lz
> /usr/bin/ld: skipping incompatible /usr/local/lib/libtiff.so when
> searching for -ltiff
> /usr/bin/ld: skipping incompatible /usr/local/lib/libtiff.a when
> searching for -ltiff
> /usr/bin/ld: skipping incompatible /usr/local/lib/libgthread-2.0.so
> <http://libgthread-2.0.so> when searching for -lgthread-2.0
> /usr/bin/ld: skipping incompatible /usr/local/lib/libglib-2.0.so
> <http://libglib-2.0.so> when searching for -lglib-2.0
> /usr/bin/ld: skipping incompatible /usr/local/lib/libavcodec.a when
> searching for -lavcodec
> /usr/bin/ld: skipping incompatible /usr/local/lib/libavcodec.a when
> searching for -lavcodec
> /usr/bin/ld: cannot find -lavcodec
> collect2: ld returned 1 exit status
> make[2]: *** [lib/libopencv_highgui.so.2.3.0] Error 1
> make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
> make: *** [all] Error 2
>
>
> So, my question is how do I get rid of "/usr/local/lib", in partiuclar
> the "-L/usr/local/lib"? I'd also love to get rid of the warnings that
> hint that for these other libs, the /usr/lib64 versions are getting
> overshadowed by /usr/local/lib versions.
>
> Thanks in advance!
> Ryan
The prominent position of -L/usr/local/lib between the object files and
the libraries to link against suggests the assumption that it's induced
by a LINK_DIRECTORIES() command. Grepping for "link_directories" in the
OpenCV source tree reveals that there are only a few occasions where
this can happen: The highgui module, TBB and IPP. You might check the
arguments of LINK_DIRECTORIES() to see if they contain a /usr/local/lib.
Regards,
Michael
PS: Which CMake version do you use?
More information about the CMake
mailing list