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
error Undefined symbols for architecture x86_64: "_hello",
referenced from: _main in ccZdSQP3.o
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With