Open waruqi opened 3 years ago
https://docs.microsoft.com/en-us/cpp/build/reference/cl-invokes-the-linker?view=msvc-160
Thanks, I use --passL:-link --passL:-libpath:dir --passL:foo.lib
to solve this problem.
nim c --cc:vcc -d:release --nimcache:build\.gens\test\windows\x64\release\nimcache --passL:-link --passL:-libpath:build\windows\x64\release --passL:foo.lib -o:build\windows\x64\release\test.exe src\main.nim
I can finally let xmake support building nim projects on windows, thank you very much. @geekrelief
$ xmake -v
[ 33%]: linking.release foo.lib
"C:\\Program Files\\nim-1.6.0\\bin\\nim" c --cc:vcc -d:release --nimcache:build\.gens\foo\windows\x64\release\nimcache --app:staticlib --noMain --passC:-DNimMain=NimMain_2D68A01A --passC:-DNimMainInne
r=NimMainInner_2D68A01A --passC:-DNimMainModule=NimMainModule_2D68A01A --passC:-DPreMain=PreMain_2D68A01A --passC:-DPreMainInner=PreMainInner_2D68A01A -o:build\windows\x64\release\foo.lib src\foo.nim
[ 66%]: linking.release test.exe
"C:\\Program Files\\nim-1.6.0\\bin\\nim" c --cc:vcc -d:release --nimcache:build\.gens\test\windows\x64\release\nimcache --passL:-link --passL:-libpath:build\windows\x64\release --passL:foo.lib -o:buil
d\windows\x64\release\test.exe src\main.nim
[100%]: build ok!
However, I think nim should be able to handle link flags better and pass them automatically to link.exe instead of cl.exe
FYI, I tested this on Windows 10, nim devel (1.7.1) with Visual Studio 2019, and I was able to compile with a single passL
with /link
as the first option passed. The order of passL
doesn't matter, i.e. passC
doesn't have to come before passL
. For example in nimble I call:
exec &"nim c --passL:\"/link /libpath:samples /libpath:samples/plugins\" {settings.join(\" \")} {nimFilePath}"
where settings
is a seq[string]
containing other options like: @["--passC:\"/wd4311 /wd4312 /wd4103 /wd4133 /wd4028\" ", "--app:lib", "--gc:arc", "-d:danger", "--nomain:on"]
ok, thanks.
I set
--cc:vcc
to build and link nim program on windows 10, but I cannot pass--passL:-libpath:xxx
to nim to link library.-libpath:
and-lfoo
seems to be passed into cl.exe and cl.exe ignored them.and nim cannot use link.exe to link them. it always call vccexe.exe to link objects and libraries.
verbose output