MinGW compilation “file not recognized: File format not recognized”

前端 未结 1 1222
别那么骄傲
别那么骄傲 2021-01-15 06:31

I\'m trying to compile a c++ program and I am having some issues. In particular, when I use x86_64-w64-mingw32-gcc as my compiler, it complains half way through my compilati

相关标签:
1条回答
  • 2021-01-15 07:04

    You are compiling your object files with a 64-bit compiler driver, w64-mingw32-gcc, and with -m64 you are explicitly directing it to generate 64-bit code (unnecessarily, as that is its default). But you are linking with a 32-bit linker that does not understand 64-bit object files.

    This is happening because in your makefile you are, unusually, invoking ld explicitly for your incremental solver linkage:

    COMMAND_LINK_SOLVER=ld -r -o $@ $^
    

    rather than delegating linkage to your compiler driver in the usual way, and a 32-bit ld from a different toolchain is being found in your PATH before the 64-bit one belonging to your mingw-w64 toolchain.

    To avoid this, invoke the linker via the compiler driver as normal, which for your solver linkage means:

    COMMAND_LINK_SOLVER=$(GXX) -Wl,-r -o $@ $^
    

    You can depend on w64-mingw32-gcc to invoke the ld that was installed with it.

    There is no need to correct your main linkage as it is already done the right way.

    0 讨论(0)
提交回复
热议问题