MinGW编译“无法识别文件:无法识别文件格式"; [英] MinGW compilation "file not recognized: File format not recognized"

查看:201
本文介绍了MinGW编译“无法识别文件:无法识别文件格式";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译c ++程序,但遇到了一些问题.特别是,当我使用x86_64-w64-mingw32-gcc作为编译器时,它在编译过程中抱怨"tmp/src/libfastms/solver/solver.cpp.o:文件未被识别:文件格式未被识别".

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

这是我的makefile(不是我的,我的,我正在尝试使此makefile适应cygwin环境) https://pastebin.com/vgnVYJUL

Here is my makefile (not mine, I'm trying to adapt this makefile to a cygwin environment) https://pastebin.com/vgnVYJUL

这是我运行make时的控制台输出:

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

其他一些注意事项:

  • 使用g ++编译时,我没有这个问题(似乎只是minGW)
  • 此问题的常见解决方案是清除残留目标文件的目录.这是行不通的.
  • 另一个常见原因是尝试编译.h文件.显然我没有这样做.

谢谢.

推荐答案

您正在使用64位编译器驱动程序w64-mingw32-gcc来编译目标文件, 并使用-m64明确地将其定向以生成64位代码(不必要地, 因为这是默认设置).但是您正在链接的32位链接器没有 了解64位目标文件.

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.

之所以发生这种情况,是因为在您的makefile中,您通常会调用ld 明确地用于增量solver链接:

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

COMMAND_LINK_SOLVER=ld -r -o $@ $^

而不是以通常的方式将链接委派给编译器驱动程序,并且 在您的PATH中找到了来自其他工具链的32位ld 属于您的mingw-w64工具链的64位.

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.

为避免这种情况,请像平常一样通过编译器驱动程序调用链接器 solver链接表示:

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 $@ $^

您可以依靠w64-mingw32-gcc来调用随它一起安装的ld.

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

由于正确的方式已经完成,因此无需更正main链接.

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

这篇关于MinGW编译“无法识别文件:无法识别文件格式";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆