I have a given makefile, written by our Professor. `
SHELL = /bin/bash
CC = gcc
CFLAGS = -Wall -W -std=c99 -pedantic
LIBS =
# Rajouter le nom des executables apres '=', separes par un espace.
# Si une ligne est pleine, rajouter '\' en fin de ligne et passer a la suivante.
# To compile without bor-util.c file
EXECS = main
# To compile with bor-util.c file
EXECSUTIL =
# To compile with bor-util.c & bor-timer.c files
EXECSTIMER =
.c.o :
$(CC) -c $(CFLAGS) $*.c
help ::
@echo "Options du make : help all clean distclean"
all :: $(EXECS) $(EXECSUTIL) $(EXECSTIMER)
$(EXECS) : %: %.o
$(CC) -o $@ $@.o $(LIBS)
$(EXECSUTIL) : %: %.o bor-util.o
$(CC) -o $@ $@.o bor-util.o $(LIBS)
$(EXECSTIMER) : %: %.o bor-util.o bor-timer.o
$(CC) -o $@ $@.o bor-util.o bor-timer.o $(LIBS)
clean ::
\rm -f *.o core
distclean :: clean
\rm -f *% $(EXECS) $(EXECSUTIL) $(EXECSTIMER)
`
All we have to do in this project, is to write our code in other file and use this makefile to compile as usual. I've written a helloWorld function to test. I have 3 files FUNCTIONS.C
#include <stdio.h>
#include "functions.h"
void printMsg(){
printf("Hello World !");
}
FUNCTIONS.H
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
void printMsg();
#endif /* FUNCTIONS_H */
And a MAIN.C file to test out everything
#include "functions.h"
int main(){
printMsg();
return 0;
}
and I've added main to the makefile. But I get this error message when I compile
gcc -o main main.o
main.o: In function `main':
main.c:(.text+0xa): undefined reference to `printMsg'
collect2: error: ld returned 1 exit status
Makefile:32: recipe for target 'main' failed
make: *** [main] Error 1
Does anyone know what's the solutions please ? Thank you