I'm getting a linker error when I try to build a small C program on CentOS 8.1. I'm new to Linux development, and to using make, and I haven't been able to solve the error. The linker is failing to resolve a function that's defined in a static library. I built the static library from the sample code for the APUE book.
I'm able to build my program, if I use a makefile that's provided with the APUE sample code. But I'm trying to get it to build with a simpler makefile that I wrote.
The program is:
#include "apue.h"
int
main(void)
{
err_exit(8, "hello world");
exit(0);
}
The relevant line from the header file is:
void err_exit(int, const char *, ...) __attribute__((noreturn));
The makefile is:
runme: testprog.o
gcc -ansi -Wall -o runme -L. -lapue testprog.o
testprog.o: testprog.c
gcc -c -ansi -Wall -o testprog.o -I. -DLINUX -D_GNU_SOURCE testprog.c
The error is:
$ make
gcc -ansi -Wall -o runme -L. -lapue testprog.o
testprog.o: In function main':
testprog.c:(.text+0x14): undefined reference to
err_exit'
collect2: error: ld returned 1 exit status
make: *** [Makefile:2: runme] Error 1
Any suggestions would be appreciated.