1 year ago
#381880

Sam Mitchell
undefined reference to function when compiling using makefiles C
I am trying to run some experiments using a set of functions inside a file called coco.c
(from the coco optimisation platform which can be found at https://github.com/numbbo/coco). This file also comes with a header file coco.h
. I have been trying to test if the calling functions from the coco.c
file works by writing my own file called testing.c
.
The full testing.c file can be seen below
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "coco.h"
#define max(a,b) ((a) > (b) ? (a) : (b))
int main(void){
coco_suite_t *suite;
suite = coco_suite("bbob-biobj", "", "");
return 0;
}
I have placed placed both coco.h
and coco.c
in the same folder as testing.c
along with my Makefile.in
. coco_suite
is a function inside coco.c
.
The makefile that I have been using can be seen below (most of which I have copied from the example makefile).
## Makefile
LDFLAGS += -lm
CCFLAGS ?= -g -ggdb --std+c89 -pedantic -Wall -Wextra -Wstrict-prototypes -Wshadow -Wno-sign-compare -Wconversion
all: testing
clean:
rm -f coco.o
rm -f testing.o testing
testing: testing.o coco.o
gcc ${CCFLAGS} -o testing coco.o testing.o ${LDFLAGS}
coco.o: coco.h coco.c
gcc -c ${CCFLAGS} -o coco.o coco.c
testing.o: coco.h coco.c testing.c
gcc -c ${CCFLAGS} -o testing.o testing.c
However, when attempting to build the executable I get an error saying undefined reference to coco_suite
. I know that the function prototype is in the header file and the full code is in the source file as I have successfully run the example provided by the authors of the coco platform. I have doublechecked the whitespace (tabs vs spaces etc) and it matches exactly with the working example provided. However even when I copy and paste the example code into the testing.c
file I get the same error.
This leads me to believe that the issue is in the makefile but I cant see what it is.
Does anyone know what the issue could be?
c
makefile
gnu-make
0 Answers
Your Answer