【Cmake学习】debug记录:CMP0004

在windows上使用cmake3.23.2编译时,出现如下错:

CMake Error at cmake/ucm.cmake:579 (add_executable):
  Target "gpuvis" links to item " C:/Program Files
  (x86)/SDL2-2.0.5/lib/x64/SDL2.lib" which has leading or trailing
  whitespace.  This is now an error according to policy CMP0004.
Call Stack (most recent call first):
  CMakeLists.txt:147 (ucm_add_target)```

查找cmake的官方文档,里面对CMP004的解释如下:

Libraries linked may not have leading or trailing whitespace.
CMake versions 2.4 and below silently removed leading and trailing whitespace from libraries linked with code like.

target_link_libraries(myexe " A ")

This could lead to subtle errors in user projects.
The OLD behavior for this policy is to silently remove leading and trailing whitespace. The NEW behavior for this policy is to diagnose the existence of such whitespace as an error. The setting for this policy used when checking the library names is that in effect when the target is created by an add_executable() or add_library() command.
This policy was introduced in CMake version 2.6.0. CMake version 3.23.2 warns when the policy is not set and uses OLD behavior. Use the cmake_policy() command to set it to OLD or NEW explicitly.

看起来是默认是OLD policy,应该只是warning而不是error,即使在Cmakelist里额外加入了cmake_policy -> OLD,还是不管用,跟官方文档里说的不一致,奇怪~~

cmake_minimum_required( VERSION 2.8 FATAL_ERROR )
cmake_policy(SET CMP0004 OLD)

Anyway,不管这个了,还是找找错在哪里吧~

查了一些资料,发现有人遇到同样的问题
他在Cmakelist里去掉空格就解决了:

set(SDL2_LIBRARIES "-L${SDL2_LIBDIR}  -lSDL2 ")   <---- here
BEFORE:    set(SDL2_LIBRARIES "-L${SDL2_LIBDIR}  -lSDL2 ")
AFTER :    set(SDL2_LIBRARIES "-L${SDL2_LIBDIR}  -lSDL2")

但是我的Cmakelist并没有这样的空格…

由于我用的cmake的gui,我又检查了一下这个里面设置的path:
在这里插入图片描述
发现SDL2_LIBRARY有两个path,中间有空格,试试删掉:
在这里插入图片描述

竟然解决了~~~
耶!!!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Daisy Wang 001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值