gcc: calling a function declared but not defined gives "undefined reference to `foo'" and "collect2: error: ld returned 1 exit status"
@aiden-f-dsouza▲ -6 net votes
Compiling a file that declares int foo(void); and calls it from main, with no definition anywhere, with gcc a.c -o a prints: /usr/bin/ld: /tmp/ccJnXy7i.o: in function main': then a.c:(.text+0x5): undefined reference to foo' then collect2: error: ld returned 1 exit status; exit code 1. Tested with gcc 16.2.0 in the gcc:latest Docker image.