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

CLang/Mingw Linker Bug When -p mingw is excluded. #958

Closed
RussellHaley opened this issue Sep 17, 2020 · 4 comments
Closed

CLang/Mingw Linker Bug When -p mingw is excluded. #958

RussellHaley opened this issue Sep 17, 2020 · 4 comments

Comments

@RussellHaley
Copy link

Describe the bug

I am using the llvm-mingw project which combines CLang and mingw-64. I noticed when configuring a project that excluding -p mingw causes the linker to fail when compiling lua due to it attempting to link directly to the dll. So these configurations work:

xmake f -v -a $arch -p mingw --toolchain=clang --mrc="$triplet-windres.exe" --mingw=$stdlib_dir
xmake config -v -a $arch -p mingw --toolchain=clang --mrc="$triplet-windres.exe" --sdk=$stdlib_dir

but this does not:

xmake config -v -a $arch --toolchain=clang --mrc="$triplet-windres.exe" --sdk=$stdlib_dir

[ 97%]: linking.release lua51.exe
error: lld: error: lld doesn't support linking directly against build\windows\x86_64\release\lua51.dll, use an import library
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)

Since the CLang lld linker cannot link against DLLs, the "Platform" should not matter, both mingw and windows should generate and use lib files for linking.

Expected behavior

The linker call generated by xmake should always use a lib file when building for platforms mingw and windows.

Feature Request

I would like to note that on *Nix and Windows, the LLVM-MinGW package always includes the sdk in a directory adjacent to bin in triplet form: <arch>-w64-migw32. It would be really slick if xmake could figure out the compiler path so one would only need to do:

xmake f -p mingw --toolchain=clang

which should default to x86_64, or optionally include an arch:

xmake f -a aarch64 -p mingw --toolchain=clang

I build the llvm-mingw toolchain on a FreeBSD host then cross compile my WinLua toolchain (which include llvm-mingw for windows) and then test the compiler in windows. The directory structure is identical on both platforms. Here is a screen shot of my WinLua install. It uses the "official" llvm-mingw build and I directly install the cmake install output.

image

Thanks!
Russ

@waruqi
Copy link
Member

waruqi commented Sep 17, 2020

I am using the llvm-mingw project which combines CLang and mingw-64. I noticed when configuring a project that excluding -p mingw causes the linker to fail when compiling lua due to it attempting to link directly to the dll. So these configurations work:

? Do you want to use clang toolchain (compiler/linker) + mingw64 sdk (headers/libraries)? Or just want to use the llvm-mingw (https://github.com/mstorsjo/llvm-mingw) toolchain?

If you want to use https://github.com/mstorsjo/llvm-mingw, we need add the llvm-mingw toolchain configuration in toolchains list of xmake. https://github.com/xmake-io/xmake/tree/master/xmake/toolchains

@waruqi
Copy link
Member

waruqi commented Sep 17, 2020

You can update to dev version (xmake update -s dev) and improve mingw to support llvm-mingw toolchain.

we need not set --toolchain= argument.

xmake f -p mingw -a [x86_64|i386|arm64|arm] --mingw=/opt/llvm-mingw
xmake

@RussellHaley
Copy link
Author

It appears that xmake f -a [x86_64|i386|arm64|arm] -p mingw --toolchain=clang does seem to work on my Windows laptop. I had tested on a different laptop previously and I was positive that the I needed the --mingw directory.

Thank you, I will start investigating toolchains.

@waruqi
Copy link
Member

waruqi commented Sep 21, 2020

--toolchain=clang? Why not xmake f -a [x86_64|i386|arm64|arm] -p mingw --mingw=/xx/llvm-mingw ?

xmake/mingw platform will use toolchain(mingw) to support llvm-mingw. The clang toolchain is only used for the usual clang compiler. (for apt install clang)

@waruqi waruqi closed this as completed Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants