简单的问题。我正在为一个简单的 c++ 项目使用 CMake 和 VSCode,我想使用 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>
.
运行时CXX=clang cmake ..
在我的 build/
目录,命令设置为/usr/bin/c++
,所以我猜这是某种别名。
有人知道我错过了什么吗?
为清楚起见,给出的错误是:
c++: error: unrecognized command line option '-fmodules'; did you mean '-fmudflap'?
最佳答案
找到了答案。 /usr/bin/c++
被认为是 POSIX 系统上的默认编译器,我的操作系统与 POSIX 兼容。 c++
是 g++
编译器的符号链接(symbolic link),所以我只是更新了符号链接(symbolic link)以指向 /usr/bin/clang
。我想这是因为我的 CMakeTools 套件只有 C 的 clang,而 cmake 假设默认的 usr/bin/c++
是我想要的 C++。
关于c++ - 如何启用clang的模块TS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55684008/