繁体   English   中英

将 object 文件链接到 Makefile 中的 C 文件时出现问题

[英]Troubles linking an object file to a C file in a Makefile

我得到了一个 object 文件set.o*以及 header 文件set.h 我需要对我创建的文件main.c中的函数运行测试。 我写了以下内容Makefile

all: main

main: main.c set.h set.o
    clang -Wall -g main.c set.o -o main

clean:
    rm main

这个Makefile一直给我错误:

ld: warning: ignoring file set.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
Undefined symbols for architecture x86_64:
  "_validateMemUse", referenced from:
      _main in main-f6a155.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1

如果有人知道我哪里出错了,将不胜感激:)

错误很明显,这里简化为我强调的重要声明:

ld:警告:忽略文件 set.o ,为 macOS-x86_64 构建但尝试链接为未知不支持的文件格式构建的文件

显然文件“set.o”是为另一个目标系统编译的,或者不是 object 文件。 在任何情况下,linker 都无法识别它,因此无法将您的“main.c”链接到它。

回到给你这个文件的人那里,并为你的 Mac 索要一个 object 文件,或者更好的来源。


注意:你的Makefile是可以的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM