I’m trying to reproduce the code of the book Effective C: An Introduction to Professional C Programming by R. Seacord
#include <stdio.h>
void swap(int, int); // defined in Listing 2-2
int main(void) {
int a = 21;
int b = 17;
swap(a, b);
printf("main: a = %d, b = %dn", a, b);
return 0;
}
When I compile the code on my MacOS 10.15.7 with gcc swap.c
, I get the following error:
Undefined symbols for architecture x86_64:
"_swap", referenced from:
_main in swap-315897.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What shall I do to correct it?