matplotlib-cpp icon indicating copy to clipboard operation
matplotlib-cpp copied to clipboard

symbol not found in flat namespace '_PyCapsule_GetPointer' when running a matplotlib cpp basic example.

Open AnshG714 opened this issue 3 years ago • 2 comments

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
)

Also, in my main method in data_measure_img_seq/main.cpp, here is what I call:

plt::plot({1, 3, 2, 4});
plt::show();

AnshG714 avatar Jun 19 '22 01:06 AnshG714

I also had the same problem

Kevinlinpr avatar Aug 16 '22 15:08 Kevinlinpr

use this config

target_include_directories(${PROJECT_NAME} PRIVATE ${Python3_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME} ${Python3_LIBRARIES})

Kevinlinpr avatar Aug 17 '22 01:08 Kevinlinpr