【发布时间】:2021-02-09 11:28:07
【问题描述】:
我在运行程序时遇到链接错误,即使 test.h 和 test.c 中的两个函数的函数签名相同:
test.h:
void function(int);
test.c:
#include "test.h"
#include "stdio.h"
static void function(int n) {
printf("%d\n", n);
}
main.c:
#include "test.h"
int main() {
function(5);
return 0;
}
这是输出:
Undefined symbols for architecture x86_64:
"_function", referenced from:
_main in ccNaA2H2.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
在课堂上,我了解到函数签名是函数名及其参数。 那么,为什么我在 main 中的程序不调用 test.h 中的 function(5) 来调用 test.c 中的 function(5) 呢?
谢谢
【问题讨论】:
标签: c linker linker-errors