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

Linker error when building with MinGW 11.2 #44

Closed
githubuser0xFFFF opened this issue May 28, 2024 · 11 comments
Closed

Linker error when building with MinGW 11.2 #44

githubuser0xFFFF opened this issue May 28, 2024 · 11 comments
Assignees
Labels
bug Something isn't working cmake CMake build system

Comments

@githubuser0xFFFF
Copy link

When I build TinyORM with MinGW 11.2 i get the following linker error:

collect2.exe: fatal error: cannot find 'ld'

I can fix this error by removing or commenting line 160 in TinyCommon.cmake: -fuse-ld=lld. The lld linker is not included in a normal MinGW distribution.

    if(MINGW)
        target_compile_options(${target} INTERFACE
            $<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-ignored-attributes>
        )

        target_link_options(${target} INTERFACE
            $<$<CONFIG:Debug,RelWithDebInfo>:
                LINKER:--dynamicbase,--high-entropy-va,--nxcompat
                LINKER:--default-image-base-high>
            # Use faster linker ( GNU ld linker doesn't work with the Clang;
            # for both GCC and Clang )
            # TODO use LINKER_TYPE target property when min. version will be CMake v3.29 silverqx
            # -fuse-ld=lld
        )
    endif()
@silverqx
Copy link
Owner

And does it compile on mingw? I'm only using msys2.

@silverqx silverqx added bug Something isn't working cmake CMake build system labels May 28, 2024
@silverqx
Copy link
Owner

Doesn't compile I'm getting compile errors, this is the first time I tried to compile with mingw-w64.

@githubuser0xFFFF
Copy link
Author

Yes, It compiles with MinGW and if I remove the line -fuse-ld=lld it also links properly. If I build the debug version I need to completely disable this part:

 target_link_options(${target} INTERFACE
            $<$<CONFIG:Debug,RelWithDebInfo>:
                LINKER:--dynamicbase,--high-entropy-va,--nxcompat
                LINKER:--default-image-base-high>
            # Use faster linker ( GNU ld linker doesn't work with the Clang;
            # for both GCC and Clang )
            # TODO use LINKER_TYPE target property when min. version will be CMake v3.29 silverqx
            # -fuse-ld=lld
        )

to link the library.

I use the MinGW distribution that is installed with the Qt installer for Qt 5.15.2. So the only problem for me is the link step.

@silverqx
Copy link
Owner

silverqx commented May 28, 2024

I tried now mingw 11.2 with Qt 6.7.1 and I have 2 more problems, it doesn't recognize --default-image-base-high linker option and also doesn't recognize this pragma #pragma GCC diagnostic ignored "-Wdangling-reference".

Now I also tried MinGW 13.1 and it works with this pragma but still doesn't recognize --default-image-base-high.

@githubuser0xFFFF
Copy link
Author

Yes, this happens if you build with debug info - to workaround this, I simply disable / remove the following part:

 target_link_options(${target} INTERFACE
            $<$<CONFIG:Debug,RelWithDebInfo>:
                LINKER:--dynamicbase,--high-entropy-va,--nxcompat
                LINKER:--default-image-base-high>
            # Use faster linker ( GNU ld linker doesn't work with the Clang;
            # for both GCC and Clang )
            # TODO use LINKER_TYPE target property when min. version will be CMake v3.29 silverqx
            # -fuse-ld=lld
        )

@silverqx
Copy link
Owner

mingw64 13.1 has outdated ld.exe v2.40, the --default-image-base-high is already fixed in ld 2.42.

@silverqx
Copy link
Owner

I have found ~7 problems:

  • --default-image-base-high
  • #pragma GCC diagnostic ignored "-Wdangling-reference"
  • -fuse-ld=lld
  • a build done with MinGW 13.1 finishes with 0 errors/warnings but I can't execute binaries, can't find an entry point in dll (this isn't happening with MinGW 11.2 tom.exe), but now I have also tried with MinGW 11.2 and the same problem with unit tests like: The procedure entry point basic_string::char_traits::replace 😮 could not be located in dyn. link library TinyOrm0d.dll, so there will be more problems with this, it can be caused by these security flags or ASLR.
  • FindMySQL.cmake package module can't find MySQL client library on MinGW
  • QtCreator cmake impl. doesn't add dll libraries on the run path with MinGW kits and I think the same problem exists for msys2?
  • ld linker is soo slooow 😂

I really recommend installing MSYS2 ucrt64, mingw-w64 is only outdated msys2 that is missing many fixes.

I look at this when I will have a more time but msys2 ucrt64 g++, clang++ builds are tested using CI pipelines with all possible cmake option combinations, static/shared/tinydrivers/g++/clang++ builds, ... here and here.
I don't plan to do this for mingw-w64 at sure.

@silverqx
Copy link
Owner

silverqx commented May 28, 2024

But it compiles with 0 warnings and errors, which is impressive for an unsupported or untested platform 😁 Problem is that it takes 30min to compile, msvc or clang got it in 3mins (I'm talking about unit tests, compiling core dll and tom.exe is pretty fast).

@githubuser0xFFFF
Copy link
Author

Ok, thank you for the quick response. I just had quick look into the documentation and the supported compilers. I missed the part that MinGW is an unsupported platform - sorry.

@silverqx
Copy link
Owner

silverqx commented May 28, 2024

Nothing to sorry, still lot of bugs in my code 😂, I leave it open so it can be fixed, sometimes, I should at least fix eg. -fuse-ld=lld because it's not a good idea to override these defaults, but problem is that all msys2 CI pipelines depends on this -fuse-ld=lld, so I will have to somehow figure it out, cmake's LINKER_TYPE or CMAKE_LINKER_TYPE is perfect for these but I can't use it right now because min. cmake version must be v3.29.

@silverqx silverqx reopened this May 28, 2024
@silverqx
Copy link
Owner

I have removed that hard-coded -fuse-ld=lld for if(MINGW) in c5b02a5, linker type can be changed using the CMAKE_LINKER_TYPE compiler definition on the cmake command line. It will be in the next release v0.38.1.

@silverqx silverqx self-assigned this Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cmake CMake build system
Projects
None yet
Development

No branches or pull requests

2 participants