silverqx / TinyORM

Modern C++ ORM library
https://www.tinyorm.org
MIT License
231 stars 25 forks source link

Linker error when building with MinGW 11.2 #44

Closed githubuser0xFFFF closed 1 month ago

githubuser0xFFFF commented 4 months ago

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 commented 4 months ago

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

silverqx commented 4 months ago

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

githubuser0xFFFF commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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

silverqx commented 4 months ago

I have found ~7 problems:

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 1 month ago

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.