c)犯错误&;链接问题:输入文件的i386:x86-64体系结构,与i386输出不兼容

c)犯错误&;链接问题:输入文件的i386:x86-64体系结构,与i386输出不兼容,c,makefile,compiler-errors,linker-errors,incompatibletypeerror,C,Makefile,Compiler Errors,Linker Errors,Incompatibletypeerror,当我在终端中键入“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 e

当我在终端中键入“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
有人能解释为什么以及如何修复它吗(

我附上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

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

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

然后,当您运行
makeclean
时,它将删除旧的内容,此时您可以再次运行make。

如果生成系统的makefile,您应该运行./configure以获取新文件,然后重新编译。

我遇到了类似的问题。我遇到的问题是,对象文件是使用i386 arichitecture生成的,我正在尝试要链接到x86_64链接器。我删除了使用x86_64选项重新生成的对象文件,并尝试再次链接。它现在可以工作了

粘贴Makefile。但问题是,正如它告诉您的,一些文件已经编译(隐式或显式地使用
-m64
),而链接目标(可能还有其他对象文件)使用
-m32
处理。Makefile看起来很好(除非你真的应该在everyfile上使用
-pthread
开关)。也许你已经从另一台机器上移动了项目,你有没有尝试过删除目标文件并重新编译?嗯……没有。我实际上在uni尝试过,效果很好(实际上Makefile是讲师给出的哈哈)…嗯,你如何删除目标文件?+1我刚刚遇到了同样的问题,谷歌把我带到了这里。运行
makeclean
后,它成功了:)