TinyORM icon indicating copy to clipboard operation
TinyORM copied to clipboard

Linker error when building with MinGW 11.2

Open githubuser0xFFFF opened this issue 1 year ago • 10 comments

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()

githubuser0xFFFF avatar May 28 '24 12:05 githubuser0xFFFF

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

silverqx avatar May 28 '24 12:05 silverqx

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

silverqx avatar May 28 '24 12:05 silverqx

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.

githubuser0xFFFF avatar May 28 '24 12:05 githubuser0xFFFF

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.

silverqx avatar May 28 '24 12:05 silverqx

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
        )

githubuser0xFFFF avatar May 28 '24 12:05 githubuser0xFFFF

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

silverqx avatar May 28 '24 13:05 silverqx

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 avatar May 28 '24 13:05 silverqx

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).

silverqx avatar May 28 '24 14:05 silverqx

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.

githubuser0xFFFF avatar May 28 '24 14:05 githubuser0xFFFF

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 avatar May 28 '24 14:05 silverqx

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 avatar Aug 22 '24 07:08 silverqx