opencv的CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(my_run_name)
find_package(OpenCV REQUIRED)
add_executable(your_executable_file test_imgread.cpp)
target_link_libraries(videostab ${OpenCV_LIBS})
linux下使用opencv的cpp代码,对应的makefile
有imread.cpp和fun2.cpp,以及fun2.h三个文件
all: out
out: imread.o fun2.o
g++ -o nice imread.o fun2.o `pkg-config --libs opencv`
imgread.o: imread.cpp
g++ -c imread.cpp `pkg-config --cflags opencv`
fun2.o: fun2.cpp
g++ -c fun2.cpp `pkg-config --cflags opencv`
如果是用CLion作为IDE,则其CMakeLists.txt写成:
cmake_minimum_required(VERSION 3.2)
project(opencv_test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
find_package(OpenCV REQUIRED)
add_executable(opencv_test ${SOURCE_FILES} source_file.h source_file.cpp)
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
也就是添加了倒数第1行和倒数第3行。