Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法找到std模块 #5615

Open
Perdixky opened this issue Sep 13, 2024 · 11 comments
Open

无法找到std模块 #5615

Perdixky opened this issue Sep 13, 2024 · 11 comments
Labels

Comments

@Perdixky
Copy link

Perdixky commented Sep 13, 2024

Xmake 版本

xmake v2.9.4+HEAD.e85b001

操作系统版本和架构

Linux Perdixky-PC 6.6.36.6-microsoft-standard-WSL2+ #1 SMP PREEMPT_DYNAMIC Fri Sep 6 16:36:32 CST 2024 x86_64 x86_64 x86_64 GNU/Linux

描述问题

我已经安装了clang-19

> clang-19 --version
Ubuntu clang version 19.1.0 (++20240903024228+0c641568515a-1~exp1~20240903144250.30)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin

但是我使用xmake的时候

> xmake
[ 50%]: cache compiling.release test.cpp
error: test.cpp:2:8: fatal error: module 'std' not found
    2 | import std;
      | ~~~~~~~^~~
1 error generated.
  > in test.cpp

期待的结果

我希望可以解决这个问题

工程配置

set_languages("c++23")
target("test")
    set_kind("binary")
    add_files("test.cpp")
    set_toolset("cc", "clang-19")
    set_toolset("cxx", "clang++-19")
    set_toolset("ld", "clang++-19")

附加信息和错误日志

> xmake -vD
[ 50%]: cache compiling.release test.cpp
clang++-19 -c -Qunused-arguments -m64 -std=c++23 -o build/.objs/test/linux/x86_64/release/test.cpp.o test.cpp
error: @programdir/core/main.lua:329: @programdir/actions/build/main.lua:148: @programdir/modules/async/runjobs.lua:325: @programdir/modules/private/action/build/object.lua:91: @programdir/modules/core/tools/gcc.lua:919:
 test.cpp:2:8: fatal error: module 'std' not found
    2 | import std;
      | ~~~~~~~^~~
1 error generated.
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]:
    [@programdir/modules/core/tools/gcc.lua:919]: in function 'catch'
    [@programdir/core/sandbox/modules/try.lua:123]: in function 'try'
    [@programdir/modules/core/tools/gcc.lua:860]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]:
    [@programdir/core/tool/compiler.lua:278]: in function 'compile'
    [@programdir/modules/private/action/build/object.lua:91]: in function 'script'
    [@programdir/modules/private/action/build/object.lua:122]: in function 'build_object'
    [@programdir/modules/private/action/build/object.lua:147]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:241]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/async/runjobs.lua:223]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:406]:

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>
@Perdixky Perdixky added the bug label Sep 13, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: clang toolchain cannot be configured

@Perdixky Perdixky changed the title clang工具链无法配置 无法找到std模块 Sep 13, 2024
@waruqi
Copy link
Member

waruqi commented Sep 18, 2024

set_toolset 删了,然后试下:

xmake f --toolchain=clang-19 --runtimes=c++_shared -cvD
xmake -rvD

不行就给下完整 logs

@Perdixky
Copy link
Author

xmake f --toolchain=clang --runtimes=c++_shared -cvD
checking for platform ... linux
checking for architecture ... x86_64
checking for clang ... /usr/bin/clang
configure
{
ccache = true
toolchain = clang
runtimes = c++_shared
host = linux
arch = x86_64
plat = linux
mode = release
ndk_stdcxx = true
clean = true
buildir = build
kind = static
}
xmake -rvD
checking for clang ... /usr/bin/clang
checking for the c++ compiler (cxx) ... clang
checking for /usr/bin/clang ... ok
checking for flags (-fPIC) ... ok
clang "-fPIC" "-Qunused-arguments" "-m64"
checking for flags (-std=c++23) ... ok
clang "-std=c++23" "-Qunused-arguments" "-m64"
[ 50%]: cache compiling.release test.cpp
/usr/bin/clang -c -Qunused-arguments -m64 -std=c++23 -stdlib=libc++ -o build/.objs/test/linux/x86_64/release/test.cpp.o test.cpp
checking for flags (-MMD -MF) ... ok
clang "-MMD" "-MF" "/dev/null" "-Qunused-arguments" "-m64"
checking for flags (-fdiagnostics-color=always) ... ok
clang "-fdiagnostics-color=always" "-Qunused-arguments" "-m64"
error: @programdir/core/main.lua:329: @programdir/actions/build/main.lua:148: @programdir/modules/async/runjobs.lua:325: @programdir/modules/private/action/build/object.lua:91: @programdir/modules/core/tools/gcc.lua:919:
test.cpp:4:8: fatal error: module 'std' not found
4 | import std;
| ~~~~~~~^~~
1 error generated.
stack traceback:
[C]: in function 'error'
[@programdir/core/base/os.lua:973]:
[@programdir/modules/core/tools/gcc.lua:919]: in function 'catch'
[@programdir/core/sandbox/modules/try.lua:123]: in function 'try'
[@programdir/modules/core/tools/gcc.lua:860]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:275]:
[@programdir/core/tool/compiler.lua:278]: in function 'compile'
[@programdir/modules/private/action/build/object.lua:91]: in function 'script'
[@programdir/modules/private/action/build/object.lua:122]: in function 'build_object'
[@programdir/modules/private/action/build/object.lua:147]: in function 'jobfunc'
[@programdir/modules/async/runjobs.lua:241]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:275]: in function 'trycall'
[@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
[@programdir/modules/async/runjobs.lua:223]: in function 'cotask'
[@programdir/core/base/scheduler.lua:406]:

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>

@waruqi
Copy link
Member

waruqi commented Sep 20, 2024

建议你还是直接自己下载 llvm 包,切到 llvm toolchain 去试下,linux 安装的 Clang 不一定带 std module 的 ,也没有 clang-scan-deps

如果用系统的,libc++, libc++-abi 包也得自己装好

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


It is recommended that you download the llvm package directly yourself and switch to the llvm toolchain to try it. Clang installed on Linux may not come with std module.

@Perdixky
Copy link
Author

我现在使用了llvm

xmake f --toolchain=llvm --runtimes=c++_shared -cvD
checking for platform ... linux
checking for architecture ... x86_64
configure
{
ccache = true
plat = linux
arch = x86_64
host = linux
kind = static
runtimes = c++_shared
toolchain = llvm
ndk_stdcxx = true
mode = release
clean = true
buildir = build
}

xmake -rvD
checking for /usr/lib/llvm-19/bin/clang ... ok
checking for flags (-fPIC) ... ok
clang "-fPIC" "-Qunused-arguments" "-m64"
checking for flags (-std=c++23) ... ok
clang "-std=c++23" "-Qunused-arguments" "-m64"
[ 50%]: cache compiling.release test.cpp
/usr/lib/llvm-19/bin/clang -c -Qunused-arguments -m64 -std=c++23 -stdlib=libc++ -cxx-isystem/usr/lib/llvm-19/include/c++/v1 -stdlib=libc++ -o build/.objs/test/linux/x86_64/release/test.cpp.o test.cpp
checking for flags (-MMD -MF) ... ok
clang "-MMD" "-MF" "/dev/null" "-Qunused-arguments" "-m64"
checking for flags (-fdiagnostics-color=always) ... ok
clang "-fdiagnostics-color=always" "-Qunused-arguments" "-m64"
error: @programdir/core/main.lua:329: @programdir/actions/build/main.lua:148: @programdir/modules/async/runjobs.lua:325: @programdir/modules/private/action/build/object.lua:91: @programdir/modules/core/tools/gcc.lua:919:
test.cpp:4:8: fatal error: module 'std' not found
4 | import std;
| ~~~~~~~^~~
1 error generated.
stack traceback:
[C]: in function 'error'
[@programdir/core/base/os.lua:973]:
[@programdir/modules/core/tools/gcc.lua:919]: in function 'catch'
[@programdir/core/sandbox/modules/try.lua:123]: in function 'try'
[@programdir/modules/core/tools/gcc.lua:860]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:275]:
[@programdir/core/tool/compiler.lua:278]: in function 'compile'
[@programdir/modules/private/action/build/object.lua:91]: in function 'script'
[@programdir/modules/private/action/build/object.lua:122]: in function 'build_object'
[@programdir/modules/private/action/build/object.lua:147]: in function 'jobfunc'
[@programdir/modules/async/runjobs.lua:241]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:275]: in function 'trycall'
[@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
[@programdir/modules/async/runjobs.lua:223]: in function 'cotask'
[@programdir/core/base/scheduler.lua:406]:

stack traceback:
[C]: in function 'error'
@programdir/core/base/os.lua:973: in function '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>

@waruqi
Copy link
Member

waruqi commented Sep 21, 2024

你配置的不对,纯 cpp 没模块文件,参考这个配置

https://github.com/xmake-io/xmake/blob/dev/tests/projects/c%2B%2B/modules/stdmodules_cpp_only/xmake.lua

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Your configuration is wrong. Pure cpp has no module files. Please refer to this configuration.

https://github.com/xmake-io/xmake/blob/dev/tests/projects/c%2B%2B/modules/stdmodules_cpp_only/xmake.lua

@Perdixky
Copy link
Author

Perdixky commented Sep 21, 2024

现在我的xmake是这样配置的
set_languages("c++23")
target("test")
set_kind("binary")
add_files("test.cpp")
set_policy("build.c++.modules", true)

然后我使用xmake f --toolchain=llvm --runtimes=c++_shared -cvD,输出:

checking for platform ... linux
checking for architecture ... x86_64
checking for clang ... /usr/lib/llvm-19/bin/clang
checking for the c++ compiler (cxx) ... clang
checking for /usr/lib/llvm-19/bin/clang ... ok
checking for flags (-fPIC) ... ok
> clang "-fPIC" "-Qunused-arguments" "-m64"
checking for flags (clang_modules) ... ok
> clang "-fmodules" "-Qunused-arguments" "-m64"
checking for flags (clang_modules_ts) ... no
> clang "-fmodules-ts" "-Qunused-arguments" "-m64"
checkinfo: @programdir/core/sandbox/modules/os.lua:273: clang: error: unknown argument: '-fmodules-ts'

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]:
checking for /usr/lib/llvm-19/bin/clang ... ok
configure
{
    host = linux
    arch = x86_64
    ccache = true
    ndk_stdcxx = true
    clean = true
    plat = linux
    kind = static
    runtimes = c++_shared
    buildir = build
    toolchain = llvm
    mode = release
}

然后我使用xmake -rvD,输出

checking for flags (clang_print_library_module_manifest_path) ... ok
> clang "-print-library-module-manifest-path" "-Qunused-arguments" "-m64"
[  0%]: <test> generating.module.deps test.cpp
checkinfo: cannot runv(/usr/lib/llvm-19/bin/clang-scan-deps --version), No such file or directory
checking for /usr/lib/llvm-19/bin/clang-scan-deps ... no
checking for flags (clang_keep_system_includes) ... ok
> clang "-E" "-fkeep-system-includes" "-Qunused-arguments" "-m64"
checking for flags (-std=c++23) ... ok
> clang "-std=c++23" "-Qunused-arguments" "-m64"
/usr/lib/llvm-19/bin/clang -Qunused-arguments -m64 -stdlib=libc++ -cxx-isystem/usr/lib/llvm-19/include/c++/v1 -stdlib=libc++ -fkeep-system-includes -E -x c++ test.cpp -o build/.gens/test/linux/x86_64/release/rules/bmi/cache/modules/574a3743/test.cpp.i
checking for flags (clang_module_file) ... ok
> clang "-fmodule-file=/tmp/.xmake1002/240921/_6C054ABC1BBD4130878FDB290C5CB260.pcm" "-Qunused-arguments" "-m64"
error: @programdir/core/main.lua:329: @programdir/actions/build/main.lua:148: @programdir/modules/async/runjobs.lua:325: ...mdir/rules/c++/modules/modules_support/clang/builder.lua:132: module dependency std required for test.cpp not found
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]: in function 'raiselevel'
    [@programdir/core/sandbox/modules/utils.lua:143]: in function 'assert'
    [...mdir/rules/c++/modules/modules_support/clang/builder.lua:132]: in function '_get_requiresflags'
    [...mdir/rules/c++/modules/modules_support/clang/builder.lua:157]: in function '_append_requires_flags'
    [...mdir/rules/c++/modules/modules_support/clang/builder.lua:226]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:241]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:973: in function '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>
warning: std and std.compat modules not found ! disabling them for the build, maybe try to add --sdk=<PATH/TO/LLVM>
warning: No clang-scan-deps found ! using fallback scanner

然后我按照提示使用xmake f --sdk=/usr/lib/llvm-19
checking for platform ... linux
checking for architecture ... x86_64

然后我再次

checking for flags (gcc_deps_format) ... no
> gcc "-fdeps-format=p1689r5"
checkinfo: @programdir/core/sandbox/modules/os.lua:273: gcc: error: unrecognized command-line option ‘-fdeps-format=p1689r5’

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]:
checking for flags (gcc_deps_file) ... no
> gcc "-fdeps-file=/tmp/.xmake1002/240921/_8A23B84F031B472081FC5E08C4151350"
checkinfo: @programdir/core/sandbox/modules/os.lua:273: gcc: error: unrecognized command-line option ‘-fdeps-file=/tmp/.xmake1002/240921/_8A23B84F031B472081FC5E08C4151350’

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]:
checking for flags (gcc_deps_output) ... no
> gcc "-fdeps-target=/tmp/.xmake1002/240921/_5CD4517BFEC149308E10D66F1F646550.o"
checkinfo: @programdir/core/sandbox/modules/os.lua:273: gcc: error: unrecognized command-line option ‘-fdeps-target=/tmp/.xmake1002/240921/_5CD4517BFEC149308E10D66F1F646550.o’

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%]: <test> generating.module.deps test.cpp
checking for flags (-std=c++23) ... ok
> gcc "-std=c++23"
checking for flags (-D_GLIBCXX_USE_CXX11_ABI=0) ... ok
> gcc "-D_GLIBCXX_USE_CXX11_ABI=0"
/usr/bin/gcc -E -x c++ -std=c++23 -D_GLIBCXX_USE_CXX11_ABI=0 test.cpp -o build/.gens/test/linux/x86_64/release/rules/bmi/cache/modules/574a3743/test.cpp.i
checking for flags (gcc_module_mapper) ... ok
> gcc "-fmodule-mapper=/tmp/.xmake1002/240921/_F8980B4F565F4220861261BCF1D21730"
error: @programdir/core/main.lua:329: @programdir/actions/build/main.lua:148: @programdir/modules/async/runjobs.lua:325: ...ramdir/rules/c++/modules/modules_support/gcc/builder.lua:102: module dependency std required for test.cpp not found
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]: in function 'raiselevel'
    [@programdir/core/sandbox/modules/utils.lua:143]: in function 'assert'
    [...ramdir/rules/c++/modules/modules_support/gcc/builder.lua:102]: in function '_get_maplines'
    [...ramdir/rules/c++/modules/modules_support/gcc/builder.lua:137]: in function '_generate_modulemapper_file'
    [...ramdir/rules/c++/modules/modules_support/gcc/builder.lua:196]: 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>
warning: GCC doesn't support module scanning ! using fallback scanner

我不知道是哪里出了问题:(

@waruqi
Copy link
Member

waruqi commented Sep 21, 2024

warning: std and std.compat modules not found ! disabling them for the build, maybe try to add --sdk=<PATH/TO/LLVM>
warning: No clang-scan-deps found ! using fallback scanner

你装的不完整,不要用 apt 系统安装 llvm ,直接从 llvm 官网,下载安装包,然后指定 sdk 使用。

@waruqi
Copy link
Member

waruqi commented Sep 21, 2024

然后我按照提示使用xmake f --sdk=/usr/lib/llvm-19
checking for platform ... linux
checking for architecture ... x86_64

你又切回 gcc 了。没指定 llvm toolchain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants