我有interface.c
:
#include "interface.h"
int main(){
}
int foo(int a, int b){
return a+b;
}
interface.h
:
#ifndef UNTITLED_INTERFACE_H
#define UNTITLED_INTERFACE_H
int foo(int a, int b);
#endif //UNTITLED_INTERFACE_H
现在,test.c
:
#include <stdio.h>
#include "interface.h"
int main(){
printf("%d \n ", foo(3,4));
}
我编译了gcc test.c -o test
但收到此错误:
Undefined symbols for architecture x86_64:
"_foo", referenced from:
_main in test-9668b6.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我不知道为什么?所有文件都在同一个文件夹中!我在网上搜索,我仍然看到我正在按照正确的步骤!有人能暗示我吗? 谢谢。