构建nim项目的时候找不到PATH里的编译器和链接器
Xmake 版本
xmake v3.0.0+dev.262293e90
操作系统版本和架构
windows 11
描述问题
创建一个nim项目
xmake create -l nim -t console test
默认编译没问题,但是没法指定编译器和链接器,始终会使用cl
nim是先编译成c,然后再编译成目标文件,我希望能指定使用的编译器
默认情况下不管是单个nim文件还是nimble项目,都会去读取nim.cfg文件。
但是即便我配置了nim.cfg,xmake构建的时候也没有读取
不管是在xmake.lua同一目录还是nim源码同一目录创建如下的nim.cfg
clang.exe = "zigcc.bat"
clang.linkerexe="zigcc.bat"
cc = "clang"
cpu = "amd64"
os = "windows"
passC = "-target x86_64-windows-gnu"
passL = "-target x86_64-windows-gnu"
d = "debug"
然后nim c xx.nim 都会报错
PS C:\Users\Administrator\temp\testnim1\test> xx
checking for C:\Users\Administrator\scoop\shims\nim.exe ... ok
checking for the nim compiler (nc) ... nim.exe
checking for C:\Users\Administrator\scoop\shims\nim.exe ... ok
checking for flags (-d:release) ... ok
> nim.exe "-d:release" "--cc:vcc"
[ 63%]: linking.release test.exe
checking for C:\Users\Administrator\scoop\shims\nim.exe ... ok
checking for the nim linker (ncld) ... nim.exe
C:\Users\Administrator\scoop\shims\nim.exe c --cc:vcc -d:release --nimcache:build\.gens\test\windows\x64\release\nimcache -o:build\windows\x64\release\test.exe src\main.nim
error: @programdir\core\main.lua:329: @programdir\actions\build\main.lua:146: @programdir\modules\async\runjobs.lua:331: @programdir\rules\nim\build\target.lua:67: @programdir\core\sandbox\modules\os.lua:273: @m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected]
@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected]
@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected]
@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected]
@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@sstd@[email protected]
@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected]
@mmain.nim.c
@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@[email protected]
LINK : fatal error LNK1181: 无法打开输入文件“x86_64-windows-gnu.obj”
ing D9002 :忽略未知选项“-target”
cl: 命令行 warning D9024 :无法识别的源文件类型“x86_64-windows-gnu”,假定为对象文件
cl: 命令行 warning D9027 :源文件“x86_64-windows-gnu”被忽略
cl: 命令行 warning D9002 :忽略未知选项“-target”
cl: 命令行 warning D9024 :无法识别的源文件类型“x86_64-windows-gnu”,假定为对象文件
cl: 命令行 warning D9027 :源文件“x86_64-windows-gnu”被忽略
cl: 命令行 warning D9002 :忽略未知选项“-target”
cl: 命令行 warning D9024 :无法识别的源文件类型“x86_64-windows-gnu”,假定为对象文件
cl: 命令行 warning D9027 :源文件“x86_64-windows-gnu”被忽略
cl: 命令行 warning D9002 :忽略未知选项“-target”
cl: 命令行 warning D9024 :无法识别的源文件类型“x86_64-windows-gnu”,假定为对象文件
cl: 命令行 warning D9027 :源文件“x86_64-windows-gnu”被忽略
cl: 命令行 warning D9002 :忽略未知选项“-target”
cl: 命令行 warning D9024 :无法识别的源文件类型“x86_64-windows-gnu”,假定为对象文件
cl: 命令行 warning D9027 :源文件“x86_64-windows-gnu”被忽略
cl: 命令行 warning D9002 :cl: 命令行 warning D9002 :忽略未知选项“-target”忽略未知选项“-target”
cl: 命令行 warning D9024 :cl: 命令行 warning D9024 :无法识别的源文件类型“x86_64-windows-gnu”,假 定为对象文件无法识别的源文件类型“x86_64-windows-gnu”,假定为对象文件
cl: 命令行 warning D9027 :cl: 命令行 warning D9027 :源文件“x86_64-windows-gnu”被忽略源文件“x86_64-windows-gnu”被忽略
CC: ../../../../scoop/apps/nim/current/lib/system/exceptions.nim
CC: ../../../../scoop/apps/nim/current/lib/std/sysatomics.nim
CC: ../../../../scoop/apps/nim/current/lib/std/private/digitsutils.nim
CC: ../../../../scoop/apps/nim/current/lib/system/dollars.nim
CC: ../../../../scoop/apps/nim/current/lib/std/exitprocs.nim
CC: ../../../../scoop/apps/nim/current/lib/std/syncio.nim
CC: ../../../../scoop/apps/nim/current/lib/system.nim
CC: main.nim
Hint: [Link]
cl: 命令行 warning D9002 :忽略未知选项“-target”
cl: 命令行 warning D9024 :无法识别的源文件类型“x86_64-windows-gnu”,假定为对象文件
Error: execution of an external program failed: 'vccexe.exe --platform:amd64 /FeC:\Users\Administrator\temp\testnim1\test\build\windows\x64\release\test.exe C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@sstd@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@mmain.nim.c.obj /nologo -target x86_64-windows-gnu '
stack traceback:
[C]: in function 'error'
[@programdir\core\base\os.lua:1075]:
[@programdir\core\sandbox\modules\os.lua:273]: in function 'runv'
[@programdir\modules\core\tools\nim.lua:151]:
[C]: in function 'xpcall'
[@programdir\core\base\utils.lua:246]:
[@programdir\rules\nim\build\target.lua:67]: in function 'build_sourcefiles'
[@programdir\rules\nim\build\target.lua:83]:
[@programdir\modules\private\action\build\target.lua:172]: in function 'jobfunc'
[@programdir\modules\async\runjobs.lua:247]:
[C]: in function 'xpcall'
[@programdir\core\base\utils.lua:246]: in function 'trycall'
[@programdir\core\sandbox\modules\try.lua:117]: in function 'try'
[@programdir\modules\async\runjobs.lua:230]: in function 'cotask'
[@programdir\core\base\scheduler.lua:406]:
stack traceback:
[C]: in function 'error'
@programdir\core\base\os.lua:1075: 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>
手动指定cc和ld也没用
PS C:\Users\Administrator\temp\testnim1\test> xmake f -c -v -D --cc=zigcc --ld=zigcc
checking for platform ... windows
checking for architecture ... x64
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64\cl.exe
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Microsoft C/C++ Compiler (x64) version ... 19.44.35211
checking for nim ... C:\Users\Administrator\scoop\shims\nim.exe
configure
{
network = public
plat = windows
ld = zigcc
builddir = build
cc = zigcc
vs = 2022
ndk_stdcxx = true
mode = release
clean = true
arch = x64
ccache = true
proxy_pac = pac.lua
proxy = socks5://127.0.0.1:7890
theme = default
host = windows
kind = static
}
PS C:\Users\Administrator\temp\testnim1\test> xx
checking for C:\Users\Administrator\scoop\shims\nim.exe ... ok
checking for the nim compiler (nc) ... nim.exe
checking for C:\Users\Administrator\scoop\shims\nim.exe ... ok
checking for flags (-d:release) ... ok
> nim.exe "-d:release" "--cc:vcc"
[ 63%]: linking.release test.exe
checking for C:\Users\Administrator\scoop\shims\nim.exe ... ok
checking for the nim linker (ncld) ... nim.exe
C:\Users\Administrator\scoop\shims\nim.exe c --cc:vcc -d:release --nimcache:build\.gens\test\windows\x64\release\nimcache -o:build\windows\x64\release\test.exe src\main.nim
error: @programdir\core\main.lua:329: @programdir\actions\build\main.lua:146: @programdir\modules\async\runjobs.lua:331: @programdir\rules\nim\build\target.lua:67: @programdir\core\sandbox\modules\os.lua:273: LINK : fatal error LNK1181: 无法打开输入文件“x86_64-windows-gnu.obj”
fg' [Conf]
Hint: used config file 'C:\Users\Administrator\scoop\apps\nim\current\config\config.nims' [Conf]
Hint: used config file 'C:\Users\Administrator\AppData\Roaming\nim\nim.cfg' [Conf]
.......................................................................
Hint: [Link]
cl: 命令行 warning D9002 :忽略未知选项“-target”
cl: 命令行 warning D9024 :无法识别的源文件类型“x86_64-windows-gnu”,假定为对象文件
Error: execution of an external program failed: 'vccexe.exe --platform:amd64 /FeC:\Users\Administrator\temp\testnim1\test\build\windows\x64\release\test.exe C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@sstd@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@mmain.nim.c.obj /nologo -target x86_64-windows-gnu '
stack traceback:
[C]: in function 'error'
[@programdir\core\base\os.lua:1075]:
[@programdir\core\sandbox\modules\os.lua:273]: in function 'runv'
[@programdir\modules\core\tools\nim.lua:151]:
[C]: in function 'xpcall'
[@programdir\core\base\utils.lua:246]:
[@programdir\rules\nim\build\target.lua:67]: in function 'build_sourcefiles'
[@programdir\rules\nim\build\target.lua:83]:
[@programdir\modules\private\action\build\target.lua:172]: in function 'jobfunc'
[@programdir\modules\async\runjobs.lua:247]:
[C]: in function 'xpcall'
[@programdir\core\base\utils.lua:246]: in function 'trycall'
[@programdir\core\sandbox\modules\try.lua:117]: in function 'try'
[@programdir\modules\async\runjobs.lua:230]: in function 'cotask'
[@programdir\core\base\scheduler.lua:406]:
stack traceback:
[C]: in function 'error'
@programdir\core\base\os.lua:1075: 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>
(看xmake源码提到nc和 ncld)但是指定nc和ncld参数会提示找不到zigcc(设置为zigcc.bat也试了),但是是有的
PS C:\Users\Administrator\temp\testnim1\test> xmake f -c -v -D --nc=zigcc.bat --ncld=zigcc.bat
checking for platform ... windows
checking for architecture ... x64
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64\cl.exe
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Microsoft C/C++ Compiler (x64) version ... 19.44.35211
configure
{
nc = zigcc.bat
builddir = build
theme = default
proxy_pac = pac.lua
kind = static
clean = true
ndk_stdcxx = true
plat = windows
ccache = true
host = windows
ncld = zigcc.bat
arch = x64
vs = 2022
network = public
mode = release
proxy = socks5://127.0.0.1:7890
}
PS C:\Users\Administrator\temp\testnim1\test> xx
error: @programdir\core\main.lua:329: @programdir\actions\build\main.lua:146: @programdir\modules\async\runjobs.lua:331: ...amdir\core\sandbox\modules\import\core\tool\compiler.lua:37: cannot find known tool script for zigcc.bat
stack traceback:
[C]: in function 'error'
[@programdir\core\base\os.lua:1075]:
[...amdir\core\sandbox\modules\import\core\tool\compiler.lua:37]: in function 'load'
[@programdir\rules\nim\build\target.lua:42]: in function 'build_sourcefiles'
[@programdir\rules\nim\build\target.lua:83]:
[@programdir\modules\private\action\build\target.lua:172]: in function 'jobfunc'
[@programdir\modules\async\runjobs.lua:247]:
stack traceback:
[C]: in function 'error'
@programdir\core\base\os.lua:1075: 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>
PS C:\Users\Administrator\temp\testnim1\test> zigcc -v
clang version 20.1.2 (https://github.com/ziglang/zig-bootstrap de424301411b3a34a8a908d8dca01a1d29f2c6df)
Target: x86_64-unknown-windows-gnu
Thread model: posix
InstalledDir: C:/Users/Administrator/scoop/apps/zig-dev/0.15.0-dev.936
PS C:\Users\Administrator\temp\testnim1\test>
看输出是去读取了nim.cfg的,但是仍然用cl,应该是xmake写死了?
期待的结果
使用nim.cfg中指定的配置进行编译
工程配置
1
附加信息和错误日志
1
Bot detected the issue body's language is not English, translate it automatically.
Title: When building nim project, no specified compiler and linker was used.
Xmake version
xmake v3.0.0+dev.262293e90
Operating system version and architecture
Windows 11
###Describe the problem
Create a nim project
xmake create -l nim -t console test
There is no problem with default compilation, but the compiler and linker cannot be specified. Cl will always be used.
nim is compiled into c first, and then compiled into the target file. I hope to specify the compiler to use
By default, whether it is a single nim file or a nimble project, the nim.cfg file will be read.
But even if I configured nim.cfg, xmake was not read when building
Whether it is in the same directory as xmake.lua or nim source code, create the following nim.cfg
clang.exe = "zigcc.bat"
clang.linkerexe="zigcc.bat"
cc = "clang"
cpu = "amd64"
os = "windows"
passC = "-target x86_64-windows-gnu"
passL = "-target x86_64-windows-gnu"
d = "debug"
Then nim c xx.nim will report an error
PS C:\Users\Administrator\temp\testnim1\test> xx
checking for C:\Users\Administrator\scoop\shims\nim.exe ... ok
checking for the nim compiler (nc) ... nim.exe
checking for C:\Users\Administrator\scoop\shims\nim.exe ... ok
Checking for flags (-d:release) ... ok
> nim.exe "-d:release" "--cc:vcc"
[63%]: linking.release test.exe
checking for C:\Users\Administrator\scoop\shims\nim.exe ... ok
checking for the nim linker (ncld) ... nim.exe
C:\Users\Administrator\scoop\shims\nim.exe c --cc:vcc -d:release --nimcache:build\.gens\test\windows\x64\release\nimcache -o:build\windows\x64\release\test.exe src\main.nim
error: @programdir\core\main.lua:329: @programdir\actions\build\main.lua:146: @programdir\modules\async\runjobs.lua:331: @programdir\rules\nim\build\target.lua:67: @programdir\core\sandbox\modules\os.lua:273: @m..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@[email protected]..@sscoop@sapps@snim@current@slib@[email protected]
@m..@s..@s..@s..@sscoop@sapps@snim@current@slib@[email protected]
@m..@s..@s..@s..@sscoop@sapps@snim@current@slib@[email protected]
@m..@s..@s..@s..@sscoop@sapps@snim@current@slib@[email protected]
@m..@s..@s..@s..@sscoop@sapps@snim@current@slib@sstd@[email protected]
@m..@s..@s..@s..@sscoop@sapps@snim@current@slib@[email protected]
@mmain.nim.c
@m..@s..@s..@s..@sscoop@sapps@snim@current@[email protected]
LINK : fatal error LNK1181: The input file "x86_64-windows-gnu.obj" cannot be opened
ing D9002: Ignore unknown option "-target"
cl: Command line warning D9024: Unrecognized source file type "x86_64-windows-gnu", assuming it is an object file
cl: Command line warning D9027: Source file "x86_64-windows-gnu" is ignored
cl: Command line warning D9002: Ignore unknown option "-target"
cl: Command line warning D9024: Unrecognized source file type "x86_64-windows-gnu", assuming it is an object file
cl: Command line warning D9027: Source file "x86_64-windows-gnu" is ignored
cl: Command line warning D9002: Ignore unknown option "-target"
cl: Command line warning D9024: Unrecognized source file type "x86_64-windows-gnu", assuming it is an object file
cl: Command line warning D9027: Source file "x86_64-windows-gnu" is ignored
cl: Command line warning D9002: Ignore unknown option "-target"
cl: Command line warning D9024: Unrecognized source file type "x86_64-windows-gnu", assuming it is an object file
cl: Command line warning D9027: Source file "x86_64-windows-gnu" is ignored
cl: Command line warning D9002: Ignore unknown option "-target"
cl: Command line warning D9024: Unrecognized source file type "x86_64-windows-gnu", assuming it is an object file
cl: Command line warning D9027: Source file "x86_64-windows-gnu" is ignored
cl: Command line warning D9002 :cl: Command line warning D9002 : Ignore unknown option "-target" Ignore unknown option "-target"
cl: Command line warning D9024 :cl: Command line warning D9024 : Unrecognized source file type "x86_64-windows-gnu", assuming that the source file type "x86_64-windows-gnu", assuming that the object file cannot be recognized, assuming that the object file is
cl: Command line warning D9027 :cl: Command line warning D9027 : Source file "x86_64-windows-gnu" is ignored Source file "x86_64-windows-gnu" is ignored
CC: ../../../../scoop/apps/nim/current/lib/system/exceptions.nim
CC: ../../../../scoop/apps/nim/current/lib/std/sysatomics.nim
CC: ../../../../scoop/apps/nim/current/lib/std/private/digitsutils.nim
CC: ../../../../scoop/apps/nim/current/lib/system/dollars.nim
CC: ../../../../scoop/apps/nim/current/lib/std/exitprocs.nim
CC: ../../../../scoop/apps/nim/current/lib/std/syncio.nim
CC: ../../../../scoop/apps/nim/current/lib/system.nim
CC: main.nim
Hint: [Link]
cl: Command line warning D9002: Ignore unknown option "-target"
cl: Command line warning D9024: Unrecognized source file type "x86_64-windows-gnu", assuming it is an object file
Error: execution of an external program failed: 'vccexe.exe --platform:amd64 /FeC:\Users\Administrator\temp\testnim1\test\build\windows\x64\release\test.exe C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@[email protected]..@sscoop@snim@scurrent@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@s..@s..@s..@s..@s..@s..@s..@sscoop@sapps@snim@current@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@s..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@sstd@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@s..@s..@s..@s..@s..@s..@sscoop@sapps@snim@current@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@s..@s..@s..@s..@s..@s..@sscoop@sapps@snim@current@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@s..@s..@s..@sscoop@sapps@snim@scurrent@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@mmain.nim.c.obj /nologo -target x86_64-windows-gnu '
stack traceback:
[C]: in function 'error'
[@programdir\core\base\os.lua:1075]:
[@programdir\core\sandbox\modules\os.lua:273]: in function 'runv'
[@programdir\modules\core\tools\nim.lua:151]:
[C]: in function 'xpcall'
[@programdir\core\base\utils.lua:246]:
[@programdir\rules\nim\build\target.lua:67]: in function 'build_sourcefiles'
[@programdir\rules\nim\build\target.lua:83]:
[@programdir\modules\private\action\build\target.lua:172]: in function 'jobfunc'
[@programdir\modules\async\runjobs.lua:247]:
[C]: in function 'xpcall'
[@programdir\core\base\utils.lua:246]: in function 'trycall'
[@programdir\core\sandbox\modules\try.lua:117]: in function 'try'
[@programdir\modules\async\runjobs.lua:230]: in function 'cotask'
[@programdir\core\base\scheduler.lua:406]:
stack traceback:
[C]: in function 'error'
@programdir\core\base\os.lua:1075: 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>
Expected results
Compile using the configuration specified in nim.cfg
Project Configuration
1
Additional information and error logs
1
如果像下面这样指定工具链可以用zigcc编译,
add_rules("mode.debug", "mode.release")
toolchain("myclang")
set_kind("standalone")
set_toolset("cc", "zigcc.bat")
set_toolset("cxx", "zigcc.bat")
set_toolset("ld", "zigcc.bat")
target("test")
set_kind("binary")
add_files("src/main.nim")
set_toolchains("myclang")
但是会提示找不到zigcc。把命令复制出来执行是不会报错的
PS C:\Users\Administrator\temp\testnim1\test> xmake f -c -v -D
checking for platform ... windows
checking for architecture ... x64
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64\cl.exe
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Microsoft C/C++ Compiler (x64) version ... 19.44.35211
checking for nim ... C:\Users\Administrator\scoop\shims\nim.exe
configure
{
kind = static
proxy = socks5://127.0.0.1:7890
clean = true
plat = windows
theme = default
network = public
ccache = true
vs = 2022
ndk_stdcxx = true
builddir = build
mode = release
proxy_pac = pac.lua
arch = x64
host = windows
}
PS C:\Users\Administrator\temp\testnim1\test> xx
checking for C:\Users\Administrator\scoop\shims\nim.exe ... ok
checking for the nim compiler (nc) ... nim.exe
checking for C:\Users\Administrator\scoop\shims\nim.exe ... ok
checking for flags (-d:release) ... ok
> nim.exe "-d:release"
[ 63%]: linking.release test.exe
checking for C:\Users\Administrator\scoop\shims\nim.exe ... ok
checking for the nim linker (ncld) ... nim.exe
C:\Users\Administrator\scoop\shims\nim.exe c -d:release --nimcache:build\.gens\test\windows\x64\release\nimcache -o:build\windows\x64\release\test.exe src\main.nim
error: @programdir\core\main.lua:329: @programdir\actions\build\main.lua:146: @programdir\modules\async\runjobs.lua:331: @programdir\rules\nim\build\target.lua:67: @programdir\core\sandbox\modules\os.lua:273: Hint: used config file 'C:\Users\Administrator\scoop\apps\nim\current\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\Administrator\scoop\apps\nim\current\config\config.nims' [Conf]
Hint: used config file 'C:\Users\Administrator\AppData\Roaming\nim\nim.cfg' [Conf]
.......................................................................
CC: ../../../../scoop/apps/nim/current/lib/system/exceptions.nim
Error: invocation of external compiler program failed. 系统找不到指定的文件。
Additional info: Requested command not found: 'zigcc.bat -c -w -ferror-limit=3 -target x86_64-windows-gnu -O3 -IC:\Users\Administrator\scoop\apps\nim\current\lib -IC:\Users\Administrator\temp\testnim1\test\src -o C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected]'. OS error: 2
stack traceback:
[C]: in function 'error'
[@programdir\core\base\os.lua:1075]:
[@programdir\core\sandbox\modules\os.lua:273]: in function 'runv'
[@programdir\modules\core\tools\nim.lua:151]:
[C]: in function 'xpcall'
[@programdir\core\base\utils.lua:246]:
[@programdir\rules\nim\build\target.lua:67]: in function 'build_sourcefiles'
[@programdir\rules\nim\build\target.lua:83]:
[@programdir\modules\private\action\build\target.lua:172]: in function 'jobfunc'
[@programdir\modules\async\runjobs.lua:247]:
[C]: in function 'xpcall'
[@programdir\core\base\utils.lua:246]: in function 'trycall'
[@programdir\core\sandbox\modules\try.lua:117]: in function 'try'
[@programdir\modules\async\runjobs.lua:230]: in function 'cotask'
[@programdir\core\base\scheduler.lua:406]:
stack traceback:
[C]: in function 'error'
@programdir\core\base\os.lua:1075: 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>
PS C:\Users\Administrator\temp\testnim1\test> zigcc.bat -c -w -ferror-limit=3 -target x86_64-windows-gnu -O3 -IC:\Users\Administrator\scoop\apps\nim\current\lib -IC:\Users\Administrator\temp\testnim1\test\src -o C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected] C:\Users\Administrator\temp\testnim1\test\build\.gens\test\windows\x64\release\nimcache\@m..@s..@s..@s..@sscoop@sapps@snim@scurrent@slib@[email protected]
PS C:\Users\Administrator\temp\testnim1\test>
像下面这样可以了,但是怪怪的 在项目目录下创建nim.cfg (需要指明zigcc的全路径,我确定PATH里面是有的)
clang.exe = "C:/path/zigcc.bat"
clang.linkerexe="C:/path/zigcc.bat"
cc = "clang"
cpu = "mips"
os = "linux"
passC = "-target mips-linux-musleabi"
passL = "-target mips-linux-musleabi"
d = "debug"
Bot detected the issue body's language is not English, translate it automatically.
It's OK like the following, but it's weird Create nim.cfg in the project directory (need to specify the full path of zigcc, I'm sure there is one in PATH)
clang.exe = "C:/path/zigcc.bat"
clang.linkerexe="C:/path/zigcc.bat"
cc = "clang"
cpu = "mips"
os = "linux"
passC = "-target mips-linux-musleabi"
passL = "-target mips-linux-musleabi"
d = "debug"
这个临时解决方案还是有问题,虽然我上面通过在nim.cfg里面指定全路径可以编译,但是当使用其他工具,比如ar的时候,nim没有提供指定llvm-ar的方式,nim会使用llvm-ar。他仍然会提示找不到(即便我的PATH里面有),这就造成没法构建静态库/动态库之类的。 感觉是xmake没有读取环境变量?
补充一句:我手动在终端里面nim配合zig创建静态库,动态库是没有问题的,也不需要在nim.cfg里面写全路径 只要xmake把从PATH寻找工具的问题解决了就没问题了
Bot detected the issue body's language is not English, translate it automatically.
There is still a problem. Although I can compile by specifying the full path in nim.cfg above, when using other tools, such as ar, nim will use llvm-ar. He will still prompt that it cannot be found (even if it is in my PATH), which will make it impossible to build static libraries/dynamic libraries or the like. Does it feel like xmake does not read environment variables?
目前 win 上 nim toolchain 是跟 msvc envs 绑定的,暂不支持切换其他工具链。
https://github.com/xmake-io/xmake/blob/84f20e464e3438603d0b35d4ab528c4924faee66/xmake/toolchains/nim/xmake.lua#L59
目前 win 上 nim toolchain 是跟 msvc envs 绑定的,暂不支持切换其他工具链。
xmake/xmake/toolchains/nim/xmake.lua
Line 59 in 84f20e4
toolchain:add("runenvs", name, value)
按我上面的描述,只要在项目下新增一个nim.cfg 就可以切换工具链了,cc和ld都可以切换,切换后能编译成功。 问题在于nim找不到我PATH环境变量下的llvm-ar (其实cc和ld也找不到,我是设置了全路径才找到) 能否解决下环境变量无效的问题呢(我把显示的命令复制出来直接执行就可以)
就算执行了runenv,也不影响PATH环境变量把
话说能不能支持下zig呢?nim配合zig真的很强,最近在路由器上做一些开发,nim的代码通过zig直接交叉编译成 mips-linux-musleabi,体积相比之前c++写的程序也要小很多。(需要的话我可以提供下相关的命令,其实和zig交叉编译的差不多,本身xmake已经支持zig交叉编译的前提下弄起来很简单)
Bot detected the issue body's language is not English, translate it automatically.
Currently, nim toolchain on win is bound to msvc envs, and switching to other toolchains is not supported.
https://github.com/xmake-io/xmake/blob/84f20e464e3438603d0b35d4ab528c4924faee66/xmake/toolchains/nim/xmake.lua#L59
Bot detected the issue body's language is not English, translate it automatically.
Currently, nim toolchain on win is bound to msvc envs, and switching to other toolchains is not supported.
xmake/xmake/toolchains/nim/xmake.lua
Line 59 in 84f20e4
toolchain:add("runenvs", name, value)
According to my description above, as long as you add a nim.cfg to the project, you can switch the toolchain, and both cc and ld can be switched. The problem is that nim cannot find the llvm-ar under my PATH environment variable (in fact, cc and ld cannot be found either. I found it only after the new full path)
目前 win 上 nim toolchain 是跟 msvc envs 绑定的,暂不支持切换其他工具链。
xmake/xmake/toolchains/nim/xmake.lua
Line 59 in 84f20e4
toolchain:add("runenvs", name, value)
貌似确实是xmake的bug。在windows的环境变量设置里面,可以加到用户变量里面,也可以加到系统变量里面。 我之前一直是加到用户环境变量里面,刚才试了下,把c:\path(包含llvm-ar在内)加到系统环境变量里面,xmake构建的时候就能找到llvm-ar了。
Bot detected the issue body's language is not English, translate it automatically.
Currently, nim toolchain on win is bound to msvc envs, and switching to other toolchains is not supported.
xmake/xmake/toolchains/nim/xmake.lua
Line 59 in 84f20e4
toolchain:add("runenvs", name, value)
It seems to be a bug in xmake. In the environment variable settings of Windows, it can be added to the user variable or to the system variable. I have been adding to the user environment variable before. I just tried it and added c:\path (including llvm-ar) to the system environment variable. When xmake is built, you can find llvm-ar.