win32:CONFIG(release, debug|release): LIBS += -L$$PWD/'../../../open cv/opencv/build/x64/vc15/lib/' -lopencv_world410 else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/'../../../open cv/opencv/build/x64/vc15/lib/' -lopencv_world410d else:unix: LIBS += -L$$PWD/'../../../open cv/opencv/build/x64/vc15/lib/' -lopencv_world410
时间: 2023-07-12 13:03:21 浏览: 157
这段代码是什么意思呢?
这段代码是在Qt项目的.pro文件中设置OpenCV库的链接路径和名称。其中,-L表示链接路径,-lopencv_world410表示链接的库文件名。根据不同的编译模式(release或debug),链接不同的库文件(opencv_world410或opencv_world410d)。针对不同的操作系统平台,链接不同的库文件(例如在Unix系统中,链接的库文件名可能与在Windows系统中不同)。
相关问题
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/'../../../open cv/opencv/build/x64/vc15/lib/' -lopencv_world410 else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/'../../../open cv/opencv/build/x64/vc15/lib/' -lopencv_world410d else:unix: LIBS += -L$$PWD/'../../../open cv/opencv/build/x64/vc15/lib/' -lopencv_world410这样链接会出现打包在别的电脑缺少这个库的情况吗,怎么解决或优化呢
是的,如果将Qt项目打包到另一台电脑上运行,但是另一台电脑上没有安装OpenCV库,那么程序就会出现链接库文件失败的错误。
为了解决这个问题,可以将OpenCV库一起打包到程序中。一种方法是将OpenCV库复制到Qt项目中,并在.pro文件中添加以下代码:
```
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libs/opencv_world410 -lopencv_world410
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/libs/opencv_world410d -lopencv_world410d
else:unix: LIBS += -L$$PWD/libs/opencv_world410 -lopencv_world410
```
其中,$$PWD表示当前.pro文件所在的路径,libs是一个文件夹,用来存放库文件。这样,在打包程序时,将OpenCV库和程序一起打包即可。
另一种方法是使用Qt的插件机制,在程序启动时动态加载库文件。这样可以减小程序的体积。可以在程序中检查OpenCV库是否存在,如果不存在则自动下载并加载库文件。
将QT += core QT -= gui CONFIG += c++11 TARGET = UavRectifyLoadLIb CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp # The following define makes your compiler emit warnings if you use # any feature of Qt which as been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS win32{ CONFIG(debug, debug|release){ DESTDIR = $$PWD/../../../../RasterManager/bin/Debug } else{ DESTDIR = $$PWD/../../../../RasterManager/bin/release } INCLUDEPATH += $$PWD/../../../include/gdal1101 DEPENDPATH += $$PWD/../../../include/gdal1101 } else{ CONFIG(debug, debug|release){ DESTDIR = $$PWD/../../../product/release32 } else{ DESTDIR = $$PWD/../../../product/release32 } } # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 unix:!macx: LIBS += -L$$PWD/../../../product/release32/ -lUAVAutoRectifyMt -lUAVAutoRectify -lUAVAutoRectifyFi INCLUDEPATH += $$PWD/../include DEPENDPATH += $$PWD/../include unix:!macx: LIBS += -L$$PWD/../../../lib/opencvf249/ -lopencv_core unix:!macx: LIBS += -L$$PWD/../../../lib/opencvf249/ -lopencv_highgui unix:!macx: LIBS += -L$$PWD/../../../lib/opencvf249/ -lopencv_imgproc INCLUDEPATH += $$PWD/../../../lib/opencvf249 DEPENDPATH += $$PWD/../../../lib/opencvf249 unix:!macx: LIBS += -L$$PWD/../../../../../../../usr/local/lib/ -lopencv_core #unix:!macx: LIBS += -L$$PWD/../../../../../../../usr/local/lib/ -lopencv_highgui unix:!macx: LIBS += -L$$PWD/../../../../../../../usr/local/lib/ -lopencv_imgproc unix:!macx: LIBS += -L$$PWD/../../../../../../../usr/local/lib/ -lopencv_features2d unix:!macx: LIBS += -L$$PWD/../../../../../../../usr/local/lib/ -lopencv_imgcodecs INCLUDEPATH += $$PWD/../../../../../../../usr/local/include DEPENDPATH += $$PWD/../../../../../../../usr/local/include unix:!macx: LIBS += -L$$PWD/../../../product/release32/ -lDEMDriver unix:!macx: LIBS += -L$$PWD/../../../product/release32/ -lProjection unix:!macx: LIBS += -L$$PWD/../../../product/release32/ -lIImage_gC QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO 转为cmake格式
根据给出的代码,可以将其转化为以下CMake代码:
```
cmake_minimum_required(VERSION 3.5)
project(UavRectifyLoadLIb LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt5Core REQUIRED)
add_executable(UavRectifyLoadLIb
main.cpp
)
target_link_libraries(UavRectifyLoadLIb
PRIVATE
Qt5::Core
UAVAutoRectifyMt
UAVAutoRectify
UAVAutoRectifyFi
DEMDriver
Projection
IImage_gC
opencv_core
opencv_highgui
opencv_imgproc
opencv_features2d
opencv_imgcodecs
)
target_include_directories(UavRectifyLoadLIb
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/gdal1101
${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/../../../lib/opencvf249
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../usr/local/include
)
if(UNIX AND NOT APPLE)
target_link_directories(UavRectifyLoadLIb
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../../../product/release32
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../usr/local/lib
)
endif()
if(WIN32)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set_target_properties(UavRectifyLoadLIb PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/../../../../RasterManager/bin/Debug
)
else()
set_target_properties(UavRectifyLoadLIb PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/../../../../RasterManager/bin/release
)
endif()
else()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set_target_properties(UavRectifyLoadLIb PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/../../../product/release32
)
else()
set_target_properties(UavRectifyLoadLIb PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/../../../product/release32
)
endif()
endif()
```
阅读全文