【问题标题】:MacOs - Compiling c++ OpenCv returns symbol(s) not found for architecture x86_64MacOs - 编译 c++ OpenCv 返回未找到架构 x86_64 的符号
【发布时间】:2019-09-04 19:42:40
【问题描述】:

我想在 MacO 上尝试this OpenCv code

我已关注this tutorial 在 MacO 上安装 OpenCv。 (在我尝试使用自制软件安装之前)

我有以下CMakeLists.txt

cmake_minimum_required(VERSION 3.1)
# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
SET(OpenCV_DIR <path>/installation/OpenCV-master/lib/cmake/opencv4)

# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)

# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS "    config: ${OpenCV_DIR}")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")

# Declare the executable target built from your sources
#add_executable(opencv_example example.cpp)
project(intro_PCA)
add_executable(myapp introduction_to_pca.cpp)

# Link your application with OpenCV libraries
#target_link_libraries(opencv_example ${OpenCV_LIBS})

include_directories(
        <path>/installation/OpenCV-master/include/opencv4
    )

install(TARGETS myapp DESTINATION ../0-BRIQUE_PCA/briquepca/)

从文件夹build 我使用以下命令编译代码:

$ cmake ..
$ cmake --build . --config Release

编译以以下错误结束:

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [myapp] Error 1
make[1]: *** [CMakeFiles/myapp.dir/all] Error 2
make: *** [all] Error 2

我发现here 应该添加以下内容:

-libopencv_core \
-libopencv_imgproc \
-libopencv_features2d \
-libopencv_highgui

但我不明白必须在我的CMakeLists.txt 中添加这些行的位置

有人有想法吗?

【问题讨论】:

    标签: c++ macos opencv ld


    【解决方案1】:

    您可以使用以下命令链接库:target_link_libraries(myapp ${OpenCV_LIBS}),它会将myapp 链接到由find_package(OpenCV REQUIRED) 定义的所有 OpenCV 库。

    【讨论】:

    • 感谢@Quang Hoang!我包含了您的答案并对我的 CMakeList.txt 进行了一些修改,现在生成了一个可执行文件
    猜你喜欢
    • 2020-09-09
    • 2015-05-31
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 2012-12-17
    • 2017-05-18
    • 1970-01-01
    相关资源
    最近更新 更多