Diagnosing an undefined reference

A project has two source files. main.c includes stats.h, which declares double mean(const double *x, int n);, and main.c calls mean. The file stats.c defines mean. A student builds with these commands:


Shell
gcc -Wall -c main.c
gcc -Wall -c stats.c
gcc main.o -o report


The first two commands succeed without warnings, but the third prints undefined reference to 'mean'. Which explanation and fix is correct?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Compiling and the Build Process Questions: