在编译C程序架构x86_64的未定义的符号 [英] undefined symbol for architecture x86_64 in compiling C program
本文介绍了在编译C程序架构x86_64的未定义的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的程序作为
demo_use.c
I have a simple program as demo_use.c
#include "libhello.h"
int main(void) {
hello();
return 0;
}
libhello.h
void hello(void);
libhello.c
#include <stdio.h>
void hello(void) {
printf("Hello, library world.\n");
}
我已经用在终端的命令
I have used the command in terminal as
gcc demo_use.c -o test
错误
适用于建筑x86_64的未定义符号:_hello
error Undefined symbols for architecture x86_64: "_hello",
这是引用:_main在ccZdSQP3.o
referenced from: _main in ccZdSQP3.o
LD:符号(S)没有发现建筑x86_64的collect2:LD返回1退出状态
ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status
推荐答案
您需要编译两个源文件一起生成二进制。用
You need to compile both the source files together to generate the binary. use
gcc demo_use.c libhello.c -o test
另外,的定义你好()
功能将缺席。因此,在链接时,链接将抛出未定义的符号
错误。
Otherwise, the definition of hello()
function will be absent. So, at linking time, linker will throw undefined symbol
error.
这篇关于在编译C程序架构x86_64的未定义的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文