这个事情主要的难点在于:
- 在mac上让CMake找到对应的python lib,经过尝试发现mac的CMake找不到pyenv的python,只能找到Cellar里面系统的库。
- 在Cellar里面的python的库用其pip3安装numpy和matplotlib:
- Pip3位置:/usr/local/Cellar/python@3.8/3.8.13_1/bin
- CMake中添加的include和lib:
include_directories("/usr/local/Cellar/python@3.8/3.8.13_1/Frameworks/Python.framework/Versions/3.8/include/python3.8")
include_directories("/usr/local/lib/python3.8/site-packages/numpy/core/include")
link_directories("/usr/local/Cellar/python@3.8/3.8.13_1/Frameworks/Python.framework/Versions/3.8/lib")
target_link_libraries(${PROJECT_NAME} python3.8)
- Matplotlibcpp.h直接添加到项目的include里面即可。
使用感受:
- 发现一个问题在于要传入vector才能绘图,因此c++里面要因此多很多转换代码,这个就比较麻烦了,cpp处理数据比较拉胯。还是直接输出数据比较方便,然后用python来看数据。这些都是坑。