【问题标题】:CMake Hash in File Name文件名中的 CMake 哈希
【发布时间】:2018-06-27 22:42:55
【问题描述】:

当我的 cpp 文件名中有散列/磅/锐利 (#) 时,我会收到类似于

的错误
Makefile:22669: warning: overriding recipe for target '.PHONY'
Makefile:22660: warning: ignoring old recipe for target '.PHONY'
Makefile:22678: warning: overriding recipe for target '.PHONY'
Makefile:22669: warning: ignoring old recipe for target '.PHONY'
Makefile:32887: *** missing separator.  Stop.

即使生成的 Makefile 似乎只有 178 行长。除了不在我的文件名中使用# 字符之外,还有什么方法可以防止这种情况发生吗?
编辑:分号(;)似乎也会导致这个问题

【问题讨论】:

  • # 表示 CMake 中的注释。
  • @drescherjm 文件名用引号引起来,CMake 没有给我任何错误,它们只是来自 Makefile
  • 您是否尝试在 CMake 中转义它们?
  • @drescherjm 是的
  • 值得一试。我没有想法。

标签: makefile cmake


【解决方案1】:

"#" 是 make 中的注释。几乎 100% 确定 CMake 在生成 makefile 时没有正确转义“#”字符。

至于为什么会看到这些错误行号,CMake 会生成大量的 makefile 并递归调用它们。您在“根”处看到的那个可能只是一个没有太多功能的顶级生成文件。您必须在 CMakeFiles 子目录中查找其他 makefile。如果您使用 CMake 生成的文件运行“make VERBOSE=1”,您将能够遵循被调用的子制作。此外,如果您查看“进入目录”消息 make prints,您可能能够找出正在谈论的 Makefile。

不过,简短的回答是,您不能在文件名中使用“#”、“$”、空格、“:”等特殊字符。

【讨论】:

  • 那么,我有没有办法从 CMake 中正确地逃脱它?我已经尝试在字符前放置一个、两个和三个反斜杠。一二还是Makefile报错,三及以上好像直接CMake报错
  • 您必须咨询 CMake 开发团队。但是,我认为您应该放弃并更改名称,以免它们包含# 或其他特殊字符。我怀疑你会成功。
【解决方案2】:

我在 CMake 生成的文件中遇到了类似的问题,文件名中包含未转义的 #,导致:

====================[ Build | MyAppDebug | Debug ]==========================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/<user>/MyApp/cmake-build-debug --target MyAppDebug -- -j 8
CMakeFiles/MyAppDebug.dir/build.make:4112: *** missing separator.  Stop.
make[2]: *** [CMakeFiles/MyAppDebug.dir/all] Error 2
make[1]: *** [CMakeFiles/MyAppDebug.dir/rule] Error 2
make: *** [MyAppDebug] Error 2

对我来说,这已在 CMake 版本 1.18.0 中得到修复。 (在 macOSX 上)所以我将此添加到我的 CMake 文件中:

cmake_minimum_required(VERSION 3.18)

【讨论】:

    猜你喜欢
    • 2017-05-30
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多