QMake:如何选择要链接的库版本

时间:2017-04-14 12:38:56

标签: qt opencv computer-vision cross-compiling qmake

有一个使用OpenCV的简单计算机视觉应用程序。我在主机系统上编译它而不是部署到NVidia Jetson TK1(这里没问题,我使用配置套件的Qt Creator)。我使用sshfs将Jetson的文件系统root挂载到托管/mnt/sysroot_tegra_tk1

问题:我刚刚在Jetson上编译了OpenCV 3.2版(已安装到主板/usr/local/lib中)。 /usr/local中仍然存在系统OpenCV 2.4版。我不知道如何在主机系统上配置qmake以交叉编译和链接新版本而不是Jetson的系统默认值。

我的.pro文件:

QT += core
QT -= gui

CONFIG += c++11

TARGET = markerExtractionChromakey
CONFIG += console
CONFIG -= app_bundle

unix: INCLUDEPATH += /usr/local/include
unix: QMAKE_LIBDIR = /usr/local/lib

unix: LIBS +=  -lopencv_imgproc\
               -lopencv_core.so\
               -lopencv_video\
               -lopencv_highgui\
               -lopencv_gpu

TEMPLATE = app

HEADERS += cameraworker.h

SOURCES += main.cpp \
           cameraworker.cpp

target.path = /home/ubuntu/alan/markerExtractionChromakey
target.files += markerExtractionChromakey
INSTALLS += target

项目链接输出:

/usr/bin/arm-linux-gnueabihf-g++ -Wl,-rpath-link,/mnt/sysroot_tegra_tk1/usr/lib
-Wl,-rpath-link,/mnt/sysroot_tegra_tk1/usr/lib/arm-linux-gnueabihf
-Wl,-rpath-link,/mnt/sysroot_tegra_tk1/lib/arm-linux-gnueabihf -mfloat-abi=hard
 --sysroot=/mnt/sysroot_tegra_tk1 -Wl,-rpath,/usr/local/qt5/lib
-o markerExtractionChromakey main.o cameraworker.o   -L/usr/local/lib
-lopencv_imgproc -lopencv_core -lopencv_video -lopencv_highgui 
-lopencv_gpu -L/opt/qt5_for_tegra/qt-everywhere-opensource-src-5.5.1/qtbase/lib 
-lQt5Core -L/mnt/sysroot_tegra_tk1/usr/lib 
-L/mnt/sysroot_tegra_tk1/lib/arm-linux-gnueabihf 
-L/mnt/sysroot_tegra_tk1/usr/lib/arm-linux-gnueabihf -lpthread 

1 个答案:

答案 0 :(得分:0)

问题解决了。关键时刻:

  1. 放置在不同位置的不同版本(使用显式soname是一个选项,但在我的情况下,库位于链接器默认范围之外)。
  2. 必须有正确的-rpath/-rpath-link来告诉链接器在哪里寻找。
  3. -rpath中指定的Jetson的默认<path to Qt>/qt-everywhere-opensource-src-5.5.1/qtbase/mkspecs/devices/linux-jetson-tk1-g++/qmake.conf位置。只需在默认目录之前添加您的目录:

    QMAKE_INCDIR += \
        $$[QT_SYSROOT]/usr/local/include \
        $$[QT_SYSROOT]/usr/include \
        $$[QT_SYSROOT]/usr/include/arm-linux-gnueabihf
    
    QMAKE_LIBDIR += \
        $$[QT_SYSROOT]/usr/local/lib \
        $$[QT_SYSROOT]/usr/lib \
        $$[QT_SYSROOT]/lib/arm-linux-gnueabihf \
        $$[QT_SYSROOT]/usr/lib/arm-linux-gnueabihf
    
    QMAKE_LFLAGS += \
        -Wl,-rpath-link,$$[QT_SYSROOT]/usr/local/lib \
        -Wl,-rpath-link,$$[QT_SYSROOT]/usr/lib \
        -Wl,-rpath-link,$$[QT_SYSROOT]/usr/lib/arm-linux-gnueabihf \
        -Wl,-rpath-link,$$[QT_SYSROOT]/lib/arm-linux-gnueabihf