【CMake报错】Cannot specify compile definitions for target “PRIVATE“ which is not built...

简介: 【CMake报错】Cannot specify compile definitions for target “PRIVATE“ which is not built...


👉博__主👈:米码收割机

👉技__能👈:C++/Python语言

👉公众号👈:测试开发自动化【获取源码+商业合作】

👉荣__誉👈:阿里云博客专家博主、51CTO技术博主

👉专__注👈:专注主流机器人、人工智能等相关领域的开发、测试技术。



报错:Cannot specify compile definitions for target “PRIVATE” which is not built by this project.

1)报错内容

CMake Error at CMakeLists.txt:72 (target_link_directories):

Cannot specify link directories for target “PRIVATE” which is not built by this project.

CMake Error at CMakeLists.txt:73 (target_compile_definitions):

Cannot specify compile definitions for target “PRIVATE” which is not built by this project.

CMake Error at CMakeLists.txt:80 (target_link_directories): Cannot

specify link directories for target “PRIVATE” which is not built by this project.

2)解决方案

这个错误提示的是在CMakeLists.txt文件中,试图为一个名为"PRIVATE"的目标设置属性,但是这个目标在项目中并不存在。

实际上,“PRIVATE”、"PUBLIC"和"INTERFACE"是target_*命令中的关键字,用于指定如何传递这些属性。

错误可能是因为没有正确地为target_*命令提供目标名称,或者目标名称和关键字的顺序被弄反了。

错误情况一

如果存在以下代码:

target_include_directories(PRIVATE ${CMAKE_SOURCE_DIR}/include)

应该更正为:

target_include_directories(YourActualTargetName PRIVATE ${CMAKE_SOURCE_DIR}/include)

错误情况二

如果存在以下代码:

target_link_directories(${ProjectName} PRIVATE ${RELEASE_LIB_DIR})

应该更正为:

target_link_directories(YourActualTargetName PRIVATE ${RELEASE_LIB_DIR})

其中,YourActualTargetName是你要设置属性的实际目标名称,



相关文章
|
1月前
|
人工智能 机器人 测试技术
【CMake报错】Cannot specify compile definitions for target “PRIVATE“ which is not built...
【CMake报错】Cannot specify compile definitions for target “PRIVATE“ which is not built...
|
14天前
|
编译器
“Could not determine which ”make“ command to run. Check the ”make“ step in the build configuration.”
“Could not determine which ”make“ command to run. Check the ”make“ step in the build configuration.”
|
1月前
target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target S
target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target S
22 0
|
Ubuntu Unix Linux
成功解决ERROR: Unable to find the development tool `cc` in your path; please make sure that you have the
成功解决ERROR: Unable to find the development tool `cc` in your path; please make sure that you have the
成功解决ERROR: Unable to find the development tool `cc` in your path; please make sure that you have the
|
1月前
解决运行qmake:Project ERROR: Cannot run compiler ‘cl‘. Output:
解决运行qmake:Project ERROR: Cannot run compiler ‘cl‘. Output:
282 0
|
7月前
|
编译器
[√]添加预处理的2个不同方式:target_compile_definitions / add_definitions
[√]添加预处理的2个不同方式:target_compile_definitions / add_definitions
90 0
关于 CMake编译出出现错误“Could not find compiler set in environment variable RC:” 的解决方法
关于 CMake编译出出现错误“Could not find compiler set in environment variable RC:” 的解决方法
关于 CMake编译出出现错误“Could not find compiler set in environment variable RC:” 的解决方法
编译OpenJDK11:configure: error: Target CPU mismatch. We are building for x86_64 but CL is for “版“; exp
编译OpenJDK11:configure: error: Target CPU mismatch. We are building for x86_64 but CL is for “版“; exp
142 0
build.xml:391: javac doesn‘t support the “nativeheaderdir“ attribute
build.xml:391: javac doesn‘t support the “nativeheaderdir“ attribute
91 0
|
开发工具 git
编译pluma:configure.ac:229: error: required file ‘pluma/mate-submodules/Makefile.in‘ not found
编译pluma:configure.ac:229: error: required file ‘pluma/mate-submodules/Makefile.in‘ not found
108 0