This basically describes how you're able to add OpenCV to your own program, if you're actually using CMake.
The text in quotes has to be replaced with your actual values/project names, for example, if my target is called myopencvthing
and I'd want to use OpenCV 2.0 or newer, then I'd setup something like this:
# First tell CMake the minimal version of CMake expected
cmake_minimum_required(VERSION 2.8)
# Define a project
project(myopencvproject)
# Tell CMake to look for OpenCV 2.0 (and tell it that it's required, not optional)
find_package(OpenCV 2.0 REQUIRED)
# Tell CMake to add the OpenCV include directory for the preprocessor
include_directories(${OpenCV_INCLUDE_DIRS})
# Add the source files to a variable
set(SOURCES main.cpp processing.cpp somethingelse.cpp)
# Define the actual executable target and the source files
add_executable(myopencvthing ${SOURCES})
# Finally, add the dependencies of our executable (i.e. OpenCV):
target_link_libraries(myopencvthing ${OpenCV_LIBS})
Now you'll just have to run CMake to create your actual makefiles or project files and then build everything, e.g.:
cd /my/build/dir
cmake /path/to/my/source
make
If CMake fails to find the specified dependencies, then you'll have to open the CMakeCache.txt
file and edit those paths by hand (or use cmake-gui
in case you prefer a more visual editor).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…