OpenCV compile error Linking CXX shared library ../../lib/libopencv_highgui.so /lib/libbz2.so.1: could not read symbols: File in wrong format

13,844

I had the same problem and my solution is remove all build file (or CMakeCache.txt) and cmake again.

The problem is that cmake finds a 32-bit library rather than the 64-bit one, which should be found in /lib64/libbz2.so or /usr/lib64/libbz2.so. Sometimes the cmake get messed up and keep using the cached variable. So if you remove the cache and cmake again, it should find the correct library.

Share:
13,844
Chan Kim
Author by

Chan Kim

Hi folks, I used to be a hardware engineer, but I am working on S/W area these years. Mostly I'll get help from this site, but I hope someday I can give helps to others. Thank you! Chan Kim visit my home page : http://chankim.dothome.co.kr

Updated on June 05, 2022

Comments

  • Chan Kim
    Chan Kim almost 2 years

    I'm trying to install OpenCV-2.4.9 on my CentOS 6.4. machine.
    I downloaded the source in ~/Downloads/opencv-2.4.9.
    from there, I did 'mkdir build; cd build'. Then did

    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON --enable-shared ..

    and did 'make -j2'.
    Below is the message I got (this is result of re-running using just 'make')

    [  3%] Built target libtiff
    [  4%] Built target opencv_core_pch_dephelp
    [  4%] Built target pch_Generate_opencv_core
    [  6%] Built target opencv_core
    [  6%] Built target opencv_ts_pch_dephelp
    [  6%] Built target pch_Generate_opencv_ts
    [  6%] Built target opencv_imgproc_pch_dephelp
    [  7%] Built target pch_Generate_opencv_imgproc
    [ 11%] Built target opencv_imgproc
    [ 11%] Built target opencv_flann_pch_dephelp
    [ 11%] Built target pch_Generate_opencv_flann
    [ 12%] Built target opencv_flann
    [ 12%] Built target opencv_highgui_pch_dephelp
    [ 12%] Built target pch_Generate_opencv_highgui
    Linking CXX shared library ../../lib/libopencv_highgui.so
    /lib/libbz2.so.1: could not read symbols: File in wrong format
    collect2: ld returned 1 exit status
    make[2]: *** [lib/libopencv_highgui.so.2.4.9] Error 1
    make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
    make: *** [all] Error 2
    

    I did some search, but no good answers. Can anybody give me a hint on what's wrong?

  • Chan Kim
    Chan Kim over 9 years
    Weipeng, thanks. After my post, I noticed this lib64 and lib problem, and had passed that libbz2 problem (by changing the $LD_LIBRARY_PATH so that /usr/lib64 comes before /usr/lib). After some days when I try this problem yesterday, I met with another problem. New captuer is here : flickr.com/photos/129456552@N07/15702597050
  • w177us
    w177us about 8 years
    Modifying LD_LIBRARY_PATH did not work for me, but sed -i 's#/lib/libbz2.so.1#/lib64/libbz2.so.1#g' CMakeCache.txt did the trick for me.
  • Max L
    Max L about 8 years
    @w177us your solution also worked for me on Fedora 21. Thanks!
  • Jomnipotent17
    Jomnipotent17 over 6 years
    @w177us your solution with sed worked for me also on centos 7. Thanks!