Linux g++ 抛出文件无法识别:文件格式无法识别错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14404445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:43:45  来源:igfitidea点击:

g++ throwing file not recognized: File format not recognized error

linuxg++libpq

提问by user1991251

getting following error with the command g++ -o test -L . -l pq

命令出现以下错误 g++ -o test -L . -l pq

libpq.so: file not recognized: File format not recognized

#file libpq.so
libpq.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), not stripped

gcc version 4.1.2 20070115 (SUSE Linux)

gcc 版本 4.1.2 20070115 (SUSE Linux)

I am getting the same error if I try to use -l dbodbcinstead of -l pq.

如果我尝试使用-l dbodbc而不是-l pq.

Note that test.cis a simple hello world program.

请注意,这test.c是一个简单的 hello world 程序。

Thanks in Advance.

提前致谢。

回答by Jonathan Wakely

file /usr/bin/g++tells you that g++itself is a 64-bit executable, i.e. it runs on a 64-bit machine, it doesn'ttell you that g++ can compile64-bit code (it's very unlikely but it couldbe a cross compiler for a completely different processor!) Use g++ -vor g++ -dumpmachineto find out what target it generates executables for.

file /usr/bin/g++告诉你它g++本身是一个 64 位可执行文件,即它在 64 位机器上运行,它并没有告诉你 g++ 可以编译64 位代码(这不太可能,但它可能是一个完全不同的交叉编译器处理器!)使用g++ -vg++ -dumpmachine找出它生成可执行文件的目标。

G++ doesn't actually use that library, it just passes the -loption to the linker, so the error is coming from the linker, ld

G++ 实际上并不使用那个库,它只是将-l选项传递给链接器,所以错误来自链接器,ld

If ldand objdumpare both saying they can't recognize the library but the same file is fine on a different machine, I would try updating or reinstalling the binutilspackage, which provides both ldand objdump.

如果ld并且objdump都说他们无法识别库但同一文件在另一台机器上没问题,我会尝试更新或重新安装binutils包,它同时提供ldobjdump.

You might have a 32-bit binutilsinstalled, so its ldand objdumpwouldn't understand the x86_64 library. Ensure you have the 64-bit (i.e. x86_64) binutils RPM installed.

您可能安装了 32 位binutils,因此它ldobjdump不会理解 x86_64 库。确保您安装了 64 位(即 x86_64)binutils RPM。