gpt4 book ai didi

c++ - MacOs - 编译 c++ OpenCv 返回未找到体系结构 x86_64 的符号

转载 作者:行者123 更新时间:2023-11-28 04:19:59 26 4
gpt4 key购买 nike

我想试试this OpenCv code在 MacO 上。

我关注了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 中的什么地方添加这些行

有人有想法吗?

最佳答案

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

关于c++ - MacOs - 编译 c++ OpenCv 返回未找到体系结构 x86_64 的符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55678775/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com