如何修复 CMake Parse error: Expected a command name, got unquoted argument with text "//"
问题:
你想使用 CMake 构建应用程序,但你看到类似这样的错误消息:
cmake_parse_error_output.txt
CMake Error at CMakeLists.txt:1:
Parse error. Expected a command name, got unquoted argument with text
"//".
-- Configuring incomplete, errors occurred!
See also "/ram/CMakeFiles/CMakeOutput.log".
Makefile:176: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1解决方案
你的 CMakeLists.txt 可能看起来像这样:
cmake_example.cmake
// 创建主可执行文件
add_executable(main main.cpp)问题在第一行:
comment_with_slashes.cpp
// 创建主可执行文件
CMake 注释以 # 开头,而不是 //!
将任何以 // 开头的注释行改为以 # 开头。在我们的示例中:
CMakeLists_example.cmake
# 创建主可执行文件
add_executable(main main.cpp)然后再次尝试构建(例如使用 cmake . 或 make)。除非你的 CMake 配置有其他问题,否则输出现在应该看起来像这样(对于简单构建):
cmake_success_output.txt
-- Configuring done
-- Generating done
-- 构建文件已写入:/ram
[100%] Built target mainCheck out similar posts by category:
CMake
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow