Closed Bright-Nabarro closed 1 month ago
Bot detected the issue body's language is not English, translate it automatically.
Title: arch cannot use c++ standard library module
xmake f --toolchain=clang --runtimes=c++_shared -c
xmake -rv
试试呢
import
;
你这也不是 std模块吧,是 std headerunits 。。这个 llvm/clang 本身的 deps scan 支持还有点问题。
std module 应该是用 import std;
参考 https://github.com/xmake-io/xmake/tree/dev/tests/projects/c%2B%2B/modules/stdmodules
Bot detected the issue body's language is not English, translate it automatically.
import
;
This is not a std module, but std headerunits. . There is still a problem with the deps scan support of llvm/clang itself.
std module should be imported std;
Reference https://github.com/xmake-io/xmake/tree/dev/tests/projects/c%2B%2B/modules/stdmodules
xmake f --toolchain=clang --runtimes=c++_shared -c xmake -rv
试试呢
❯ xmake f --toolchain=clang --runtimes=c++_shared -c checking for platform ... linux checking for architecture ... x86_64 ❯ xmake -vD checking for flags (clang_print_library_module_manifest_path) ... no
clang "-print-library-module-manifest-path" "-Qunused-arguments" "-m64" checkinfo: @programdir/core/sandbox/modules/os.lua:273: clang: error: unknown argument: '-print-library-module-manifest-path'
stack traceback:
[C]: in function 'error'
[@programdir/core/base/os.lua:973]:
[@programdir/core/sandbox/modules/os.lua:273]: in function 'runv'
[@programdir/modules/detect/tools/gcc/has_flags.lua:42]:
[ 0%]:
clang "-fvisibility-inlines-hidden" "-Qunused-arguments" "-m64" checking for flags (-O3) ... ok clang "-O3" "-Qunused-arguments" "-m64" checking for flags (-std=c++20) ... ok clang "-std=c++20" "-Qunused-arguments" "-m64" checking for flags (-DNDEBUG) ... ok clang "-DNDEBUG" "-Qunused-arguments" "-m64" /usr/sbin/clang-scan-deps --format=p1689 -- /usr/sbin/clang -x c++ -c src/main.cpp -o build/.objs/hello/linux/x86_64/release/src/main.cpp.o -Qunused-arguments -m64 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -std=c++20 -stdlib=libc++ -DNDEBUG error: Error while scanning dependencies for src/main.cpp: src/main.cpp:1:8: error: header file
(aka '/usr/sbin/../include/c++/v1/iostream') cannot be imported because it is not known to be a header unit
stack traceback: [C]: in function 'error' @programdir/core/base/os.lua:977: in function 'base/os.raiselevel' (...tail calls...) @programdir/core/main.lua:329: in upvalue 'cotask' @programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>
import ;
你这也不是 std模块吧,是 std headerunits 。。这个 llvm/clang 本身的 deps scan 支持还有点问题。
std module 应该是用 import std;
参考 https://github.com/xmake-io/xmake/tree/dev/tests/projects/c%2B%2B/modules/stdmodules
使用import std; 能够在系统上正常编译运行
Bot detected the issue body's language is not English, translate it automatically.
import ;
This is not a std module, but std headerunits. . There is still a problem with the deps scan support of llvm/clang itself.
std module should be imported std;
Reference https://github.com/xmake-io/xmake/tree/dev/tests/projects/c%2B%2B/modules/stdmodules
Use import std; to compile and run normally on the system
那不是好了么。。
/usr/sbin/clang-scan-deps --format=p1689 -- /usr/sbin/clang -x c++ -c src/main.cpp -o build/.objs/hello/linux/x86_64/release/src/main.cpp.o -Qunused-arguments -m64 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -std=c++20 -stdlib=libc++ -DNDEBUG error: Error while scanning dependencies for src/main.cpp: src/main.cpp:1:8: error: header file (aka '/usr/sbin/../include/c++/v1/iostream') cannot be imported because it is not known to be a header unit
clang-scan-deps 这个最新版 都还没很好支持 headerunit ,这个你要到 llvm/clang 那边去反馈。。
@Bright-Nabarro pacman 安装的 llvm 已经支持 import std 了吗
Xmake 版本
2.9.4
操作系统版本和架构
Linux DESKTOP-3STVTCR 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 GNU/Linux
描述问题
gcc与clang使用import<...>导入标准库模块无法成功编译
期待的结果
hello world!
工程配置
附加信息和错误日志
❯ xmake -vD [ 0%]: generating.module.deps src/main.cpp
/usr/sbin/gcc -m64 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -std=c++20 -fmodules-ts -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -E -x c++ src/main.cpp -MT build/.gens/hello/linux/x86_64/release/rules/bmi/cache/modules/2d9b7c0b/main.cpp.json -MD -MF build/.gens/hello/linux/x86_64/release/rules/bmi/cache/modules/2d9b7c0b/main.cpp.d -fdeps-format=p1689r5 -fdeps-file=build/.gens/hello/linux/x86_64/release/rules/bmi/cache/modules/2d9b7c0b/main.cpp.json -fdeps-target=build/.objs/hello/linux/x86_64/release/src/main.cpp.o -o build/.gens/hello/linux/x86_64/release/rules/bmi/cache/modules/2d9b7c0b/main.cpp.i
In module imported at src/main.cpp:1:1:
/usr/include/c++/14.2.1/iostream: error: failed to read compiled module: No such file or directory
/usr/include/c++/14.2.1/iostream: note: compiled module file is 'gcm.cache/./usr/include/c++/14.2.1/iostream.gcm'
/usr/include/c++/14.2.1/iostream: note: imports must be built before being imported
/usr/include/c++/14.2.1/iostream: fatal error: returning to the gate for a mechanical issue
compilation terminated.
error: @programdir/core/main.lua:329: @programdir/actions/build/main.lua:148: @programdir/modules/async/runjobs.lua:325: @programdir/core/sandbox/modules/os.lua:378: execv(/usr/sbin/gcc -m64 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -std=c++20 -fmodules-ts -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -E -x c++ src/main.cpp -MT build/.gens/hello/linux/x86_64/release/rules/bmi/cache/modules/2d9b7c0b/main.cpp.json -MD -MF build/.gens/hello/linux/x86_64/release/rules/bmi/cache/modules/2d9b7c0b/main.cpp.d -fdeps-format=p1689r5 -fdeps-file=build/.gens/hello/linux/x86_64/release/rules/bmi/cache/modules/2d9b7c0b/main.cpp.json -fdeps-target=build/.objs/hello/linux/x86_64/release/src/main.cpp.o -o build/.gens/hello/linux/x86_64/release/rules/bmi/cache/modules/2d9b7c0b/main.cpp.i) failed(1)
stack traceback:
[C]: in function 'error'
[@programdir/core/base/os.lua:973]:
[@programdir/core/sandbox/modules/os.lua:378]:
[@programdir/core/sandbox/modules/os.lua:291]: in function 'vrunv'
[...s/c++/modules/modules_support/gcc/dependency_scanner.lua:53]: in function 'callback'
[@programdir/modules/core/project/depend.lua:217]: in function 'on_changed'
[...s/c++/modules/modules_support/gcc/dependency_scanner.lua:40]: in function 'generate_dependency_for'
[...rules/c++/modules/modules_support/dependency_scanner.lua:227]: in function 'jobfunc'
[@programdir/modules/async/runjobs.lua:241]:
stack traceback: [C]: in function 'error' @programdir/core/base/os.lua:973: in function 'base/os.raiselevel' (...tail calls...) @programdir/core/main.lua:329: in upvalue 'cotask' @programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>