C语言 c)make error&link 问题:输入文件的 i386:x86-64 架构,与 i386 输出不兼容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7027018/
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-09-02 09:21:52  来源:igfitidea点击:

c )make error& link problem: i386:x86-64 architecture of input file, incompatible with i386 output

cmakefilecompiler-errorslinker-errorsincompatibletypeerror

提问by user890040

I have this output with error message when i type "make" in terminal!!

当我在终端中输入“make”时,我有这个带有错误信息的输出!!

gcc test1.o dispatchQueue.o -o test1 -pthread
/usr/bin/ld: i386:x86-64 architecture of input file `test1.o' is incompatible with i386     output
/usr/bin/ld: final link failed: Invalid operation
collect2: ld returned 1 exit status
make: *** [test1] Error 1

Is there anyone who can explain why and how to fix it? :(

有没有人可以解释为什么以及如何解决它?:(

I'm attaching makefile just in case

我附上makefile以防万一

# Comment out the targets you don't want.

# Runs all of the tests.
all: test1 test2 test3 test4 test5 testFor
    ./test1
    ./test2
    ./test3
    ./test4
    ./test5
    ./testFor

test1: test1.o dispatchQueue.o
    gcc test1.o dispatchQueue.o -o test1 -pthread

test1.o: test1.c
    gcc -c test1.c

test2: test2.o dispatchQueue.o
    gcc test2.o dispatchQueue.o -o test2 -pthread

test2.o: test2.c
    gcc -c test2.c

test3: test3.o dispatchQueue.o
    gcc test3.o dispatchQueue.o -o test3 -pthread

test3.o: test3.c
    gcc -c test3.c

test4: test4.o dispatchQueue.o
    gcc test4.o dispatchQueue.o -o test4 -pthread

test4.o: test4.c
    gcc -c test4.c

test5: test5.o dispatchQueue.o
    gcc test5.o dispatchQueue.o -o test5 -pthread

test5.o: test5.c
    gcc -c test5.c

testFor: testFor.o dispatchQueue.o
    gcc testFor.o dispatchQueue.o -o testFor -pthread

testFor.o: testFor.c
    gcc -c testFor.c

dispatchQueue.o: dispatchQueue.c dispatchQueue.h
    gcc -c dispatchQueue.c

回答by Kenji

You probably have some old files (at least test1.o) compiled for i386-x64. You can remove these old files and run make again. If you can modify the Makefile try adding a line such as:

您可能有一些为 i386-x64 编译的旧文件(至少是 test1.o)。您可以删除这些旧文件并再次运行 make。如果您可以修改 Makefile,请尝试添加一行,例如:

clean:
    rm *.o test1 test2 test3 test4 test5 testFor

Then when you run make cleanit'll remove the old stuff, at which point you can run make again.

然后当你运行make clean它会删除旧的东西,此时你可以再次运行 make 。

回答by mopa

I had similar problem. Problem for me was that object files were generated with i386 arichitecture and I was trying to link with x86_64 linker. I deleted object files generated them anew with x86_64 options and tried to linking again. It works now

我有类似的问题。对我来说问题是目标文件是用 i386 架构生成的,我试图用 x86_64 链接器链接。我删除了使用 x86_64 选项重新生成它们的目标文件,并尝试再次链接。它现在有效

回答by Tama

If the makefile is generated for the system, you should run ./configure to get new ones, and then recompile.

如果为系统生成了makefile,则应该运行./configure 来获取新的,然后重新编译。