Qt Creator Error: cannot find -lopencv_imgcodecs
Qt Creator Error: cannot find -lopencv_imgcodecs
我已经在 ubuntu 15.10 上通过 VMware 在 windows.
安装了 opencv、qt、qt creator、cmake
opencv 安装 在此目录中:/home/majidalaeinia/opencv/
将 project repository 克隆到此目录中:/home/majidalaeinia/Desktop/imgwarp-opencv/
我想在 qt creator 中 运行 the project through its CMakeLists.txt,当我在 qt creator 上按 Build now 时,出现以下错误:
error: cannot find -lopencv_imgcodecs
error: collect2: error: ld returned 1 exit status
问题出在哪里,如何解决?
@ Majid Alaeinia,从您发布的 CMakeLists.txt
文件中,没有指定 CMAKE
应该如何找到您的项目请求的库。也没有 target_link_libraries
声明,所以 CMAKE
不知道在哪里 link 它们。希望以下小示例模板对您的项目有所帮助:
cmake_minimum_required (VERSION 3.1)
project(yourProject)
find_package( OpenCV REQUIRED )
find_package( Qt5 REQUIRED COMPONENTS Sql )
### this is for c++11
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
### QT stuff if you want a GUI
set(CMAKE_AUTOMOC ON) # autogenerate qt gui features
set(CMAKE_AUTORCC ON) # used for QT resource Files (if you need)
## Additional operation...
# From here you are specifically linking all OpenCV libraries and executables
### Add executables
add_executable(yourExecutable main/main.cpp ui/res/res.qrc ${SRCS} ${UI_HDRS} ${UI_SRCS})
target_link_libraries (yourProject example Qt5::Widgets ${OpenCV_LIBS} Qt5::Sql)
### Add Library
add_library(yourProject_lib SHARED ${SRCS} ${UI_HDRS})
target_link_libraries (yourProject_lib example Qt5::Widgets ${OpenCV_LIBS})
@ Majid Alaeinia,我上传了存储库并检查了代码。如果你进入 demo
文件夹并用我在下面提供的文件更改当前的 CMakeLists.txt
文件,它应该编译(它确实在我提供的更改下编译):
project(demo)
cmake_minimum_required(VERSION 2.6)
find_package(Qt5 REQUIRED COMPONENTS Widgets Core)
FIND_PACKAGE( OpenCV REQUIRED )
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/lib ${CMAKE_CURRENT_SOURCE_DIR})
set(demo_SRCS main.cpp projfile.cpp deformwin.cpp myimage.cpp singlephotoview.cpp pointspaint.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#qt5_automoc(${demo_SRCS})
QT5_WRAP_CPP(QOBJ_CPP ${demo_SRCS})
qt5_wrap_ui(helloworld_FORMS_HEADERS deformwin.ui)
add_executable(demo ${demo_SRCS} ${helloworld_FORMS_HEADERS})
target_link_libraries(demo ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} imgwarp-lib opencv_core opencv_imgproc opencv_imgcodecs)
存储库中的代码是旧代码,仍然带有 Qt4
作为主要包装器。我认为您的计算机上可能安装了 Qt5
,事实上我提供的代码适用于 Qt5
。将其用作 src
文件夹中存在的其他 CMakeLists.txt
文件的指南并进行相应更改。
CMake
会编译但是因为它被使用 Qt4
你需要弄清楚要添加的最重要的模块,例如包含 QtGui/QApplication
的新标准通常被替换为QtWidgets/QApplication
我还想留下我之前的答案,以防您需要起点或初始模板。我希望这能澄清更多,并能帮助您推进您的项目。
我已经在 ubuntu 15.10 上通过 VMware 在 windows.
安装了 opencv、qt、qt creator、cmakeopencv 安装 在此目录中:/home/majidalaeinia/opencv/
将 project repository 克隆到此目录中:/home/majidalaeinia/Desktop/imgwarp-opencv/
我想在 qt creator 中 运行 the project through its CMakeLists.txt,当我在 qt creator 上按 Build now 时,出现以下错误:
error: cannot find -lopencv_imgcodecs
error: collect2: error: ld returned 1 exit status
问题出在哪里,如何解决?
@ Majid Alaeinia,从您发布的 CMakeLists.txt
文件中,没有指定 CMAKE
应该如何找到您的项目请求的库。也没有 target_link_libraries
声明,所以 CMAKE
不知道在哪里 link 它们。希望以下小示例模板对您的项目有所帮助:
cmake_minimum_required (VERSION 3.1)
project(yourProject)
find_package( OpenCV REQUIRED )
find_package( Qt5 REQUIRED COMPONENTS Sql )
### this is for c++11
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
### QT stuff if you want a GUI
set(CMAKE_AUTOMOC ON) # autogenerate qt gui features
set(CMAKE_AUTORCC ON) # used for QT resource Files (if you need)
## Additional operation...
# From here you are specifically linking all OpenCV libraries and executables
### Add executables
add_executable(yourExecutable main/main.cpp ui/res/res.qrc ${SRCS} ${UI_HDRS} ${UI_SRCS})
target_link_libraries (yourProject example Qt5::Widgets ${OpenCV_LIBS} Qt5::Sql)
### Add Library
add_library(yourProject_lib SHARED ${SRCS} ${UI_HDRS})
target_link_libraries (yourProject_lib example Qt5::Widgets ${OpenCV_LIBS})
@ Majid Alaeinia,我上传了存储库并检查了代码。如果你进入 demo
文件夹并用我在下面提供的文件更改当前的 CMakeLists.txt
文件,它应该编译(它确实在我提供的更改下编译):
project(demo)
cmake_minimum_required(VERSION 2.6)
find_package(Qt5 REQUIRED COMPONENTS Widgets Core)
FIND_PACKAGE( OpenCV REQUIRED )
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/lib ${CMAKE_CURRENT_SOURCE_DIR})
set(demo_SRCS main.cpp projfile.cpp deformwin.cpp myimage.cpp singlephotoview.cpp pointspaint.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#qt5_automoc(${demo_SRCS})
QT5_WRAP_CPP(QOBJ_CPP ${demo_SRCS})
qt5_wrap_ui(helloworld_FORMS_HEADERS deformwin.ui)
add_executable(demo ${demo_SRCS} ${helloworld_FORMS_HEADERS})
target_link_libraries(demo ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} imgwarp-lib opencv_core opencv_imgproc opencv_imgcodecs)
存储库中的代码是旧代码,仍然带有 Qt4
作为主要包装器。我认为您的计算机上可能安装了 Qt5
,事实上我提供的代码适用于 Qt5
。将其用作 src
文件夹中存在的其他 CMakeLists.txt
文件的指南并进行相应更改。
CMake
会编译但是因为它被使用 Qt4
你需要弄清楚要添加的最重要的模块,例如包含 QtGui/QApplication
的新标准通常被替换为QtWidgets/QApplication
我还想留下我之前的答案,以防您需要起点或初始模板。我希望这能澄清更多,并能帮助您推进您的项目。