I have been working on a c Program that is now quite large and I want to separate some of the functions out to a separate source file.
I have a working Makefile for the compilation:
Code:
all: park
park: park.c park.h
gcc -Wall -pedantic -ansi -g -I/usr/include/mysql park.c \
-L/usr/lib/mysql -lmysqlclient -lcurses -o park
I then set up a new blank database.c file to start moving some functions to. I then changed the Makefile this to:
Code:
all: park
park: park.o database.o
gcc -o park park.o database.o
park.o: park.c park.h
gcc -c -Wall -pedantic -ansi -g -I/usr/include/mysql park.c \
-L/usr/lib/mysql -lmysqlclient -lcurses
database.o: database.c
gcc -c database.c
But I have obviously misunderstood the examples I have been looking at because this produces errors
Code:
gcc -o park park.o database.o
park.o: In function `database_start':
/usr/local/src/park/park.c:5: undefined reference to `mysql_init'
/usr/local/src/park/park.c:6: undefined reference to `mysql_real_connect'
/usr/local/src/park/park.c:8: undefined reference to `mysql_error'
/usr/local/src/park/park.c:8: undefined reference to `mysql_errno'
park.o: In function `readfirst':
/usr/local/src/park/park.c:19: undefined reference to `mysql_query'
[Over a thousand lines deleted]
/usr/local/src/park/park.c:2162: undefined reference to `stdscr'
/usr/local/src/park/park.c:2162: undefined reference to `wrefresh'
park.o: In function `main':
/usr/local/src/park/park.c:2170: undefined reference to `initscr'
/usr/local/src/park/park.c:2175: undefined reference to `endwin'
collect2: ld returned 1 exit status
make: *** [park] Error 1
I cannot figure out why joining the two object files seems to lose the definition from park.h and what I am doing wrong here.
Paul