-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
Can't link with lib files made by MSVC with -static #305
Comments
Just to be clear, I've never seen a case where someone would do that. Mixing libraries made by 2 different compilers will potentially causes problems, due to incompatible CRT, debug symbol format, etc etc. With that said, what's the error from the linker? |
Oh , I just found that the problem is actually that the linker ignore the lib files of DLL if "--static". I tested mingw-w64, if I set "--static",it will link statically mostly and link agaist libs dynamically if they can't be link statically. |
Llvm-mingw should be able to link against import libraries made by MSVC just fine. GCC based toolchains (that use binutils for linking) has had some problems with that earlier, but it should work better with recent releases (and there are some fixes that will be part of the next release too). Mixing toolchains at this level is supposed to work - but if the libraries use different CRTs, and share CRT objects ( Mixing static libraries between MSVC and mingw is not supported in general (neither with GCC/binutils based toolchains not with LLVM based ones). It might work by pure luck in some cases, but it can’t be relied upon. |
To be able to reproduce this issue, you need to tell more exactly what your files are named and exactly what command you execute which behaves differently. |
I am sorry for that. The linker of CGO runs the command blow: and reports error below:
md.lib and trader.lib are placed in D:\Libs\windows\x64 . I remove the "--static" flag and then it works well.
if "--static" not set:
This issue is sovled , but if I need support the two compilers , I have to set defferent flags of linker. |
Sounds like cgo needs to fix that then, anyway glad that your problem is solved. |
I observed that GNU ld indeed does look for I think it'd be good to reopen this bug until this is fixed in a release, but with modified issue subject. |
(Sorry, I posted the wrong review url above; I edited the comment above. The correct one is https://reviews.llvm.org/D135651.) |
Reopening this again, until the fix is released. |
The fix for this issue is now available as the prerelease with LLVM 16.0.0 RC 1 is available: https://github.com/mstorsjo/llvm-mingw/releases/tag/20230130 |
This matches how ld.bfd works in practice; this fixes mstorsjo/llvm-mingw#305. Adding a test for the new lib name combination that this allows, but also adding a few negative tests for combinations that aren't matched when -static is specified (because this change in itself didn't break any of the existing tests either). The logic in how ld.bfd looks for various libraries based on an -l<libname> argument is rather complex; the ldemul_open_dynamic_archive function looks for various combinations: https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=ld/emultempl/pep.em;h=e68d1e69f17ad73af065b6bed19ae89ded913172;hb=b51c2fec1da205ea3e7354cbb3e253018d64873c#l2066 This function is only called if looking for dynamic libraries (i.e. if -static wasn't specified): https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=ld/ldfile.c;h=731ae5f7aedcf921bd36a1b32a3e0f5bfa189071;hb=b51c2fec1da205ea3e7354cbb3e253018d64873c#l365 However even this function is skipped, it still looks for libraries in the form of "lib<libname>.a" (this is what lld did before): https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=ld/ldfile.c;h=731ae5f7aedcf921bd36a1b32a3e0f5bfa189071;hb=b51c2fec1da205ea3e7354cbb3e253018d64873c#l440 But it also calls a format specific function called ldemul_find_potential_libraries, which for PE targets looks for files named "<libname>.lib": https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=ld/emultempl/pep.em;h=e68d1e69f17ad73af065b6bed19ae89ded913172;hb=b51c2fec1da205ea3e7354cbb3e253018d64873c#l2175 Differential Revision: https://reviews.llvm.org/D135651
MinGW-w64 can link with lib files made by MSVC, but llvm-mingw dosen't support?
The text was updated successfully, but these errors were encountered: