符号未发现Matplotlibcpp的错误,用CMAKE构建

发布于 2025-02-08 10:27:23 字数 1782 浏览 1 评论 0 原文

我正在尝试将CMAKE在我的C ++项目中加入MatplotlibCpp(我是CMAKE和C ++的新手)。我正在关注用于设置CMAKE文件。该项目构建正常,但是当我尝试运行可执行文件时,这是我遇到的错误:

dyld[73245]: symbol not found in flat namespace 
'_PyCapsule_GetPointer'
zsh: abort      ./data_measure_img_seq

我不确定如何解决此问题。有什么建议吗?作为参考,我将我的cmakelists文件放在下面:

# set the minimum version
cmake_minimum_required(VERSION "3.13")

# set project
project(image-data-cv)

set(OpenCV_DIR /Users/anshgodha/Developer/opencv/install/lib/cmake/opencv4)
set(CMAKE_CXX_STANDARD 14)

find_package( OpenCV REQUIRED )

include_directories( ${OpenCV_INCLUDE_DIRS} )

# for matplotlibcpp
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)
find_package(PythonLibs 3.0 REQUIRED)
include_directories(${PYTHON3_INCLUDE_DIRS} ${NumPy_INCLUDE_DIRS})

include(FetchContent)
FetchContent_Declare(
    matplotlib
    GIT_REPOSITORY https://github.com/lava/matplotlib-cpp.git
    GIT_TAG        f23347fca25219d1c42cbb91608b5556814bf572
)
FetchContent_GetProperties(matplotlib)
if(NOT matplotlib_POPULATED)
    FetchContent_Populate(matplotlib)
endif()
include_directories(SYSTEM ${matplotlib_SOURCE_DIR})

set(PROJECTS basic_data_measures;data_measure_img_seq)
foreach(PROJECT ${PROJECTS})
  add_executable(${PROJECT} ${PROJECT}/main.cpp)
  target_link_libraries(${PROJECT} PUBLIC ${OpenCV_LIBS})
  set_target_properties(${PROJECT} PROPERTIES OUTPUT_NAME "${PROJECT}")
endforeach(PROJECT ${PROJECTS})

# link python and numpy
target_link_libraries(data_measure_img_seq
    PRIVATE
        ${PYTHON_LIBRARIES}
        Python3::NumPy
)

I am trying to use CMake for including Matplotlibcpp in my C++ project (I am new to both CMake and C++). I am following https://github.com/lava/matplotlib-cpp/issues/236#issuecomment-716510547 for setting up a CMake file. The project builds fine, but when I try to run the executable, here is the error I get:

dyld[73245]: symbol not found in flat namespace 
'_PyCapsule_GetPointer'
zsh: abort      ./data_measure_img_seq

I'm not sure how to resolve this. Any suggestions? For reference, I am putting my CMakeLists file below:

# set the minimum version
cmake_minimum_required(VERSION "3.13")

# set project
project(image-data-cv)

set(OpenCV_DIR /Users/anshgodha/Developer/opencv/install/lib/cmake/opencv4)
set(CMAKE_CXX_STANDARD 14)

find_package( OpenCV REQUIRED )

include_directories( ${OpenCV_INCLUDE_DIRS} )

# for matplotlibcpp
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)
find_package(PythonLibs 3.0 REQUIRED)
include_directories(${PYTHON3_INCLUDE_DIRS} ${NumPy_INCLUDE_DIRS})

include(FetchContent)
FetchContent_Declare(
    matplotlib
    GIT_REPOSITORY https://github.com/lava/matplotlib-cpp.git
    GIT_TAG        f23347fca25219d1c42cbb91608b5556814bf572
)
FetchContent_GetProperties(matplotlib)
if(NOT matplotlib_POPULATED)
    FetchContent_Populate(matplotlib)
endif()
include_directories(SYSTEM ${matplotlib_SOURCE_DIR})

set(PROJECTS basic_data_measures;data_measure_img_seq)
foreach(PROJECT ${PROJECTS})
  add_executable(${PROJECT} ${PROJECT}/main.cpp)
  target_link_libraries(${PROJECT} PUBLIC ${OpenCV_LIBS})
  set_target_properties(${PROJECT} PROPERTIES OUTPUT_NAME "${PROJECT}")
endforeach(PROJECT ${PROJECTS})

# link python and numpy
target_link_libraries(data_measure_img_seq
    PRIVATE
        ${PYTHON_LIBRARIES}
        Python3::NumPy
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔小萌 2025-02-15 10:27:23

我遇到了使用CMAKE编译的相同问题。也许随附的cmake无法正确链接所有内容。我用例如

g++ fill.cpp -o fill -std=c++11 -I/usr/include/python2.7 -lpython2.7

I was having the same issue compiling using cmake. Perhaps the included cmake doesn't link everything properly. I got around it using e.g.

g++ fill.cpp -o fill -std=c++11 -I/usr/include/python2.7 -lpython2.7
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文