gcc错误:错误的ELF类:ELFCLASS64
我试图使用外部编译对象 coreset.o 来编译程序。 我编写了 public01.c 测试文件,我的函数位于computation.c 中,两者都可以编译。 然而,它未能将其链接在一起。 可能是什么问题?
gcc -o public01.x public01.o computation.o coreset.o
ld: fatal: file coreset.o: wrong ELF class: ELFCLASS64
ld: fatal: File processing errors. No output written to public01.x
collect2: ld returned 1 exit status
I was trying to compile a program using an external compiled object coreset.o. I wrote the public01.c test file and my functions are in computation.c, both of which compiles. However its failing on linking it together. What might be the problem?
gcc -o public01.x public01.o computation.o coreset.o
ld: fatal: file coreset.o: wrong ELF class: ELFCLASS64
ld: fatal: File processing errors. No output written to public01.x
collect2: ld returned 1 exit status
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我认为 coreset.o 是为 64 位编译的,并且您将其与 32 位computation.o 链接。
您可以尝试使用gcc(1) 的'-m64'标志重新编译computation.c
I think that coreset.o was compiled for 64-bit, and you are linking it with a 32-bit computation.o.
You can try to recompile computation.c with the '-m64' flag of gcc(1)
您可以指定“-m32”或“-m64”来选择编译模式。
在处理 autoconf(配置)脚本时,我通常在环境中设置 CC="gcc -m64" (或 CC="gcc -m32"),以便所有内容都以正确的位数进行编译。 至少,通常......人们会找到无数的方法来让它不太有效,但我的击球率非常高(远超过 95%)。
You can specify '-m32' or '-m64' to select the compilation mode.
When dealing with autoconf (configure) scripts, I usually set CC="gcc -m64" (or CC="gcc -m32") in the environment so that everything is compiled with the correct bittiness. At least, usually...people find endless ways to make that not quite work, but my batting average is very high (way over 95%) with it.
事实证明,我使用的编译器版本与使用 coreset.o 完成的编译版本不匹配。
一个是 32 位,另一个是 64 位。 如果其他人遇到类似的问题,我会保留这个。
It turns out the compiler version I was using did not match the compiled version done with the coreset.o.
One was 32bit the other was 64bit. I'll leave this up in case anyone else runs into a similar problem.
看起来目标文件是在 64 位工具链上编译的,而您正在使用 32 位工具链。 您是否尝试过以 32 位模式重新编译目标文件?
It looks like the object file was compiled on a 64-bit toolchain, and you're using a 32-bit toolchain. Have you tried recompiling the object file in 32-bit mode?
当我尝试在 Ubuntu 中运行现有的二进制文件时,出现此错误。 我修复了:
我不确定 3 个库中的哪一个做到了这一点,但我相信它是第三个。
I got this error when trying to run an existing binary in Ubuntu. I fixed with:
I'm not sure which of the 3 libs did it, but I believe it was the 3rd one.