按照网站上给出的说明构建错误

Build errors while following the instructions given on a website

您好,我已尝试按照本网站的说明进行操作 http://robotica.unileon.es/mediawiki/index.php/Objects_recognition_and_position_calculation_(webcam)

在他们要求添加的部分:

find_package(OpenCV "VERSION" REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
...
target_link_libraries("PROGRAM_NAME" ${OpenCV_LIBS})

我添加并尝试构建包,但它导致了错误:

Parse error.  Expected a command name, got unquoted argument with text "...".
-- Configuring incomplete, errors occurred!
make: *** [cmake_check_build_system] Error 1
Invoking "make cmake_check_build_system" failed

谁能帮我解决这个错误?

我认为您应该将 "VERSION" 和 "PROGRAM_NAME" 替换为版本号和程序名称。 这是 2.4 版本 和 程序名称由您命名的可执行文件命名。

这基本上描述了如何将 OpenCV 添加到您自己的程序中,如果您实际使用的是 CMake。

引号中的文本必须替换为您的实际 values/project 名称,例如,如果我的目标名为 myopencvthing 并且我想使用 OpenCV 2.0 或更新版本,那么我设置如下:

# 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})

现在您只需要 运行 CMake 来创建您实际的 makefile 或项目文件,然后构建所有内容,例如:

cd /my/build/dir
cmake /path/to/my/source
make

如果 CMake 找不到指定的依赖项,则您必须打开 CMakeCache.txt 文件并手动编辑这些路径(或者使用 cmake-gui 以防您更喜欢更直观的编辑器).