cmake报错Targets may link only to libraries. CMake is dropping the item.

Posted xiang_freedom

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cmake报错Targets may link only to libraries. CMake is dropping the item.相关的知识,希望对你有一定的参考价值。

系统: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

问题解决。

以上是关于cmake报错Targets may link only to libraries. CMake is dropping the item.的主要内容,如果未能解决你的问题,请参考以下文章

cmake报错Targets may link only to libraries. CMake is dropping the item.

CMake中link_libraries的使用

CMake中link_libraries的使用

已解决CMake Error: Cannot determine link language for target “xxx“. CMake Error: CMake can not determ

已解决CMake Error: Cannot determine link language for target “xxx“. CMake Error: CMake can not determ

OpenCV4.x进行Cmake时报错“Error in configuration process,project files may be invalid“需要的五个文件