【发布时间】:2019-09-05 03:07:29
【问题描述】:
简单的问题。我将 CMake 和 VSCode 用于一个简单的 c++ 项目,并且我想使用 clang 的模块 TS。 -fmodules 和 fmodules-ts 我都试过了,但两个标志都无法识别。
我的 CMakeLists.txt 文件:
add_executable(test
test.cpp
)
set_target_properties(test
PROPERTIES
CXX_STANDARD 20
)
target_compile_options(test
PRIVATE
"-fmodules" # or "-fmodules-ts"
"-Wall"
"-Wextra"
"-Wnon-virtual-dtor"
"-Wnoexcept"
"-Wconversion"
)
并且,在构建目录的compile-commands.json文件中,编译时使用的命令是这样的:
/usr/bin/c++ -g -fmodules -Wall ... -std=gnu++2a -o <destination> -c <my .cpp file>.
在我的build/ 目录中运行CXX=clang cmake .. 时,命令设置为/usr/bin/c++,所以我猜它是某种别名。
有人知道我错过了什么吗?
为清楚起见,给出的错误是:
c++: error: unrecognized command line option '-fmodules'; did you mean '-fmudflap'?
【问题讨论】:
-
你用的是哪个clang版本?
-
Clang 8.0.0。我的 CMakeTools 工具包说
Using compilers: C = /usr/bin/clang-8 -
也许
/usr/bin/c++不是clang?尝试运行/usr/bin/c++ --version或只检查/usr/bin/c++(可能是符号链接或某些前端)引导的位置。 -
天哪,
/usr/bin/c++ --version输出 GCC 8.2.1。好吧,猜猜这是我的问题。不知道 cmake 不会正确地将其设置为 clang。 -
@VTT 我想通了。显然
/usr/bin/c++被认为是我系统的默认 c++ 编译器,并且是 g++ 的符号链接。我把它改成了 clang,它现在可以编译了。