【问题标题】:c )make error& link problem: i386:x86-64 architecture of input file, incompatible with i386 outputc)make error&链接问题:输入文件的i386:x86-64架构,与i386输出不兼容
【发布时间】:2011-10-25 00:23:20
【问题描述】:

当我在终端中输入“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

【问题讨论】:

  • 粘贴 Makefile。但是,正如它告诉您的那样,问题是某些文件已被编译(隐式或显式使用-m64),而链接目标(可能还有其他目标文件)是使用-m32 处理的。
  • Makefile 看起来不错(除非您真的应该在每个文件上使用-pthread 开关)。也许您已经从另一台机器上移动了项目,您是否尝试过删除目标文件并重新编译?
  • 嗯.. 不.. 我实际上在 uni 试过这个并且效果很好(实际上 Makefile 是讲师给出的哈哈).. 嗯如何删除目标文件?

标签: c makefile compiler-errors linker-errors incompatibletypeerror


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

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

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

      【讨论】:

      • +1 我也遇到了同样的问题,谷歌把我带到了这里。运行make clean 后它工作了:)
      猜你喜欢
      • 2013-10-12
      • 2019-01-18
      • 2011-07-04
      • 2020-06-18
      • 1970-01-01
      • 1970-01-01
      • 2015-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多