系统:macOS
代码:
find_package(PythonInterp 3.0)
find_package(PythonLibs 3.0)
target_link_libraries(target,${PYTHON_LIBRARIES})
报错:
Targets may link only to libraries. CMake is dropping the item.
打印PYTHON_LIBRARIES的值:
/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib
这里 提到cmake实际需要完整的dylib的路径才能找到。
查找cmake文档发现find_package(PythonLibs)已废弃:
用新的FindPython3:
find_package(Python3 COMPONENTS Interpreter Development NumPy)
target_link_libraries(target,${Python3_LIBRARIES})
Python3_LIBRARIES的值为:
/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib
问题解决。