You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 16.04下如何升级libjpeg.so.8至libjpeg.so.9?及OpenCV库缺失问题

Hey there, let's tackle your issues one by one. I've run into similar linker headaches on Ubuntu 16.04 when working with OpenCV and custom library versions, so here's a step-by-step breakdown of fixes:

1. Resolve libjpeg.so.9 and libpng16.so.16 Linker Warnings

Ubuntu 16.04 ships with older versions of these libraries (libjpeg.so.8 and libpng12.so.12 by default), so when you upgrade to v9 and v16, the system's dynamic linker doesn't know where to find them. Here's how to fix that:

a. First, Locate the Libraries

First, confirm where your upgraded libraries are installed. Run these commands in the terminal:

find /usr/local/lib /usr/lib -name "libjpeg.so.9"
find /usr/local/lib /usr/lib -name "libpng16.so.16"

Most self-compiled libraries end up in /usr/local/lib, so that's the most likely path.

b. Update the Dynamic Linker Cache

Tell the system to search /usr/local/lib for libraries by adding it to the linker config:

  1. Open (or create) the local linker config file:
    sudo nano /etc/ld.so.conf.d/local.conf
    
  2. Add this line to the file:
    /usr/local/lib
    
  3. Save and exit, then update the linker cache:
    sudo ldconfig -v
    
  4. Verify the fix by checking if the linker can find the libraries:
    ldconfig -p | grep libjpeg.so.9
    ldconfig -p | grep libpng16.so.16
    
    You should see the full path to each library listed.

c. Adjust Your Application's Build Configuration

If you're still seeing warnings during compilation, make sure your build system knows where to find the libraries:

  • For CMake projects: Add these lines to your CMakeLists.txt:
    # Add path to custom libraries
    link_directories(/usr/local/lib)
    
    # Ensure the binary finds libraries at runtime
    set(CMAKE_INSTALL_RPATH "/usr/local/lib")
    set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
    
  • For Makefile projects: Update your LDFLAGS to include the library path and runtime path:
    LDFLAGS += -L/usr/local/lib -Wl,-rpath=/usr/local/lib
    

If the above steps don't work, you can create a symbolic link from the library's location to a directory the linker checks by default. Note: This can break other apps that depend on the older library versions, so only do this if necessary:

sudo ln -s /usr/local/lib/libjpeg.so.9 /usr/lib/x86_64-linux-gnu/libjpeg.so.9
sudo ln -s /usr/local/lib/libpng16.so.16 /usr/lib/x86_64-linux-gnu/libpng16.so.16
sudo ldconfig

Since you mentioned Qt problems, here are solutions to the most frequent ones paired with OpenCV:

a. Linker Can't Find Qt Libraries

Ensure your build system is pointing to the correct Qt installation:

  • For CMake: Add these lines to locate and link Qt components (adjust components based on your app's needs):
    find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui)
    include_directories(${Qt5_INCLUDE_DIRS})
    link_libraries(Qt5::Core Qt5::Widgets Qt5::Gui)
    
  • For qmake: Update your .pro file to include the necessary modules and paths:
    QT += core widgets gui
    INCLUDEPATH += /path/to/your/qt/include # Omit if Qt is in default paths
    LIBS += -L/path/to/your/qt/lib -lQt5Core -lQt5Widgets -lQt5Gui
    

b. Version Conflict Between OpenCV and Qt

If OpenCV was compiled with a different Qt version than your app, you'll run into runtime errors. Fix this by recompiling OpenCV with your Qt version:

  1. When configuring OpenCV with CMake, set these flags (adjust the Qt path to match your installation):
    cmake -D CMAKE_BUILD_TYPE=RELEASE \
          -D WITH_QT=ON \
          -D Qt5_DIR=/path/to/qt/lib/cmake/Qt5 \
          -D CMAKE_INSTALL_PREFIX=/usr/local \
          ..
    
  2. Recompile and reinstall OpenCV:
    make -j$(nproc)
    sudo make install
    

c. Runtime Plugin Errors (e.g., "Could not load the Qt platform plugin")

If your app complains about missing Qt plugins, set the QT_PLUGIN_PATH environment variable to point to your Qt's plugin directory:

export QT_PLUGIN_PATH=/path/to/qt/plugins

You can add this line to your ~/.bashrc file to make it permanent.


内容的提问来源于stack exchange,提问作者raggot

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:32:45