我已经通过Windows上的VMware在 ubuntu 15.10 上安装了opencv,qt,qt创建器,cmake。
opencv已安装在以下目录中:/home/majidalaeinia/opencv/
project repository被克隆到以下目录:/home/majidalaeinia/Desktop/imgwarp-opencv/
我想在{t}创建器中通过the project运行CMakeLists.txt,当我在qt创建器上按立即生成时,出现以下错误:
error: cannot find -lopencv_imgcodecs
error: collect2: error: ld returned 1 exit status
问题出在哪里,我该如何解决?
答案 0 :(得分:2)
@ Majid Alaeinia,您发布的CMakeLists.txt
文件中未指定CMAKE
如何找到项目中请求的库。另外,没有声明target_link_libraries
,因此CMAKE
不知道链接它们的位置。希望以下小示例模板对您的项目有所帮助:
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})
答案 1 :(得分:1)
@ 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
上使用。将其用作CMakeLists.txt
文件夹中另一个src
文件的指南,并进行相应的更改。
CMake
将会编译,但是由于使用了Qt4
,因此您需要弄清楚要添加的最重要的模块,例如,包含QtGui/QApplication
的新标准通常由{{ 1}}
如果您需要起点或初始模板,我也想留下我以前的答案。我希望这可以澄清更多内容,并可以使您的项目继续前进。