我在test.c
中有以下内容
#include <stdio.h>
#include "stdfn.h"
int main(void)
{
printOut(10, "Hello, world!\n");
//bash("say hello world");
}
资料来源:https://github.com/KrasnayaSecurity/HydroCarbon
当我试图编译时,我会得到这个错误:
President-JohnHEden:HydroCarbon aleksandr$ gcc test.c -o test -Wall
Undefined symbols for architecture x86_64:
"_printOut", referenced from:
_main in test-134873.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
发布于 2014-11-12 06:26:05
在这里,您的链接器无法找到printOut()
函数的定义。
您已经通过嵌入printOut()
在您的test.c
文件中包含了stdfn.h
声明,但是test.c
中没有该函数的定义。该定义存在于stdfn.c
中。因此,您需要将两个文件合并在一起才能生成二进制文件。
将编译行更改为
gcc test.c stdfn.c -o test -Wall
发布于 2014-11-12 06:52:32
你可以做一个
gcc test.c stdfn.c -o test -Wall
(假定stdfn.c是printOut()的定义所在),以便将包含用户定义函数的文件链接到当前使用它的文件。
https://stackoverflow.com/questions/26880575
复制相似问题