Hey guys. This is my first time posting on here, so please bear with me. I'm having a bit of a problem with a simple makefile. I've got two .c files, one of which is a library file that, for now, contains one function. The problem is, when I run make, it either completely ignores this file, or complains that it can't find it. First I'll post the makefile, then the specific error it gives me.
CC = gcc
INCLUDES = -I./include
CFLAGS = -g $(INCLUDES)
LIBDIR = ./lib
LIBS = $(LIBDIR)/libfdr.a
EXECUTABLES = test_malloc
all: $(EXECUTABLES)
clean:
rm -f src/*.o bin/*
test_malloc: src/test_malloc.o
$(CC) $(CFLAGS) -o ./bin/test_malloc ./src/test_malloc.o ./src/jmalloc.o $(LIBS)
test_malloc.o: test_malloc.c
%(CC) -c $(CFLAGS) ./src/test_malloc.c
jmalloc.o: jmalloc.c
%(CC) -c $(CFLAGS) ./src/jmalloc.c |
The problem file here is jmalloc.c. Well, now it's giving me this, after removing the .o file manually:
gcc: ./src/jmalloc.o: No such file or directory |
Before it was saying that it couldn't find ./src/jmalloc.c to run the rule for jmalloc.c, or something. That was before I manually did it from the shell for the first time, and now it'll just completely ignore it.
There's one other problem I'm having with compiling as well. I'm getting the following warning from the compiler whenever I recompile test_malloc:
src/test_malloc.c:34: warning: cast to pointer from integer of different size |
This occurs anyway I call my version of malloc. Here's an example of such a line from test_malloc.c:
1 2
|
int * a;
a = (int*)jmalloc(sizeof(int));
|
And jmalloc() is defined like this:
void * malloc(unsigned int size)
So I'm really lost on this one. I'm casting a void * as an int *, just like you would do for a regular malloc call, which also returns a void*. So why the warning? I'm not even sure what it is. I've checked and double checked, I know that the int * is the same size as the void* being returned, etc.
Any help with this stuff would be appreciated. Hope this post isn't too damn long. Thanks guys.