Fix Cross Compilation for Windows
Xmake 版本
2.9.9
操作系统版本和架构
Windows 10
描述问题
Cross compilation doesn't works for windows host.
期待的结果
Cross compilation should work for windows
工程配置
package("glfw")
add_deps("cmake")
set_sourcedir("glfw-3.4")
on_install(function (package)
local configs = {}
import("package.tools.cmake")
cmake.install(package, configs)
end)
package_end()
add_requires("glfw")
target("glad")
set_kind("static")
add_files("glad/src/*.c")
add_headerfiles("glad/include/glad/*.h")
add_headerfiles("glad/include/KHR/*.h")
add_includedirs("glad/include",{public=true})
target("hi")
set_kind("binary")
add_files("src/*.cpp")
add_deps("glad")
add_packages("glfw")
if is_plat("windows") then
add_syslinks("opengl32", "gdi32", "user32", "shell32")
elseif is_plat("linux") then
add_syslinks("GL", "m", "dl", "X11", "pthread")
end
xmake config --toolchain=llvm --plat=linux --arch=x86_64 --sdk=C:\devtools\llvm\
This fails, so do this
xmake config --toolchain=llvm --plat=cross --cross=x86_64-pc-linux-gnu
and this
xmake config --toolchain=llvm --plat=cross `
--cross=x86_64-pc-linux-gnu `
--sdk=C:/devtools/llvm `
--cxflags=C:/devtools/sysroots/deb `
--ldflags=C:/devtools/sysroots/deb
and this
xmake config --toolchain=llvm --plat=linux --arch=x86_64 --sdk=C:\devtools\llvm\ --runtimes=stdc++_shared
附加信息和错误日志
I could write a lot, but the main thing is standard library cannot be found anad pacakge install fails due to not finding os specifics stuff like pthread
you can add -vD to see verbose logs and debug it.
https://github.com/xmake-io/xmake/blob/2b88ba37fa0a9957b8ab24cf1bf6da59e2c39f21/xmake/toolchains/llvm/xmake.lua#L66
or try and wait this patch. https://github.com/xmake-io/xmake/pull/6380
Is there anything I can do to help resolve this issue more quickly? I'd like to move on to new challenges and experiments, but I feel stuck.
I have improved it. https://github.com/xmake-io/xmake/pull/6471
xmake f -p cross --cross=x86_64-pc-linux-gnu --toolchain=llvm --sdk=C:\xxx\llvm -cvD
but std header has been not supported yet
This example still doesn't compile hi.zip
with this
xmake f -p cross --cross=x86_64-pc-linux-gnu --toolchain=llvm --sdk=C:\dev\sysroots\deb2 -cvD
I'm on the dev branch as can be seen here
xmake --version
xmake v3.0.0+dev.bfc0f75db, A cross-platform build utility based on Lua
Also custom toolchains don't work for cmake packages,
I can cross compile with custom toolchain without third party packages
I assume these:
- When cross compiling llvm doesn't use lld and -fuse-ld=lld, which are necessary when compiling by hand
- CMake package install doesn't work with cross compilation. It doesn't use the cross compiler toolchain, it defaults to msvc
What probably needs to be done:
- Llvm toolchain linker should be changed to lld and -fuse-ld=lld should be default.
- SDK directory should be passed into cmake package as sysroot
- We should be able to specify toolchains in packages, so that cmake would use clang
I have improved it. #6471
xmake f -p cross --cross=x86_64-pc-linux-gnu --toolchain=llvm --sdk=C:\xxx\llvm -cvDbut std header has been not supported yet
But llvm toolchain with sdk works now in native compilation, so big thanks. Previously I had to use clang without providing sdk path in the past
@waruqi full example here
https://github.com/mccakit/Bug-Report