MinGW compilation "file not recognized: File format not recognized"
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.
Alex Kyriazis
Updated on June 05, 2022Comments
-
Alex Kyriazis almost 2 years
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 compilation saying "tmp/src/libfastms/solver/solver.cpp.o: file not recognized: File format not recognized".
Here is my makefile (not mine, I'm trying to adapt this makefile to a cygwin environment) https://pastebin.com/vgnVYJUL
Here is the console output when I run make:
x86_64-w64-mingw32-gcc -c -o tmp/src/libfastms/solver/solver.cpp.o src/libfastms/solver/solver.cpp -Wall -O3 -m64 -Isrc/libfastms -DDISABLE_OPENMP -DDISABLE_OPENCV -DDISABLE_CUDA x86_64-w64-mingw32-gcc -c -o tmp/src/libfastms/solver/solver_base.cpp.o src/libfastms/solver/solver_base.cpp -Wall -O3 -m64 -Isrc/libfastms -DDISABLE_OPENMP -DDISABLE_OPENCV -DDISABLE_CUDA x86_64-w64-mingw32-gcc -c -o tmp/src/libfastms/solver/solver_host.cpp.o src/libfastms/solver/solver_host.cpp -Wall -O3 -m64 -Isrc/libfastms -DDISABLE_OPENMP -DDISABLE_OPENCV -DDISABLE_CUDA x86_64-w64-mingw32-gcc -c -o tmp/src/libfastms/util/has_cuda.cpp.o src/libfastms/util/has_cuda.cpp -Wall -O3 -m64 -Isrc/libfastms -DDISABLE_OPENMP -DDISABLE_OPENCV -DDISABLE_CUDA x86_64-w64-mingw32-gcc -c -o tmp/src/libfastms/util/image_mat.cpp.o src/libfastms/util/image_mat.cpp -Wall -O3 -m64 -Isrc/libfastms -DDISABLE_OPENMP -DDISABLE_OPENCV -DDISABLE_CUDA ld -r -o tmp/src/libfastms/libfastms.o tmp/src/libfastms/solver/solver.cpp.o tmp/src/libfastms/solver/solver_base.cpp.o tmp/src/libfastms/solver/solver_host.cpp.o tmp/src/libfastms/util/has_cuda.cpp.o tmp/src/libfastms/util/image_mat.cpp.o tmp/src/libfastms/solver/solver.cpp.o: file not recognized: File format not recognized Makefile:167: recipe for target 'tmp/src/libfastms/libfastms.o' failed make: *** [tmp/src/libfastms/libfastms.o] Error 1
Some other notes:
- I don't have this problem when I compile with g++ (only seems to be minGW)
- A common solution to this problem is to clean the directory of residual object files. This does not work.
- Another common reason for this is trying to compile .h files. Obviously I am not doing this.
Thanks in advance.