Trouble with makefile

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.
edit: I just figured out my problem with my makefile. I'm still at a loss as to why the compiler is throwing warnings at me. As far as I know, I'm doing the same thing as I do when calling regular malloc, just casting a Void * into some other pointer, but it obviously doesn't complain with malloc.
Last edited on
You used tabs, ¿right?
Your makefile will create a ./test_malloc.o, but you want a ./src/test_malloc.o

Don't know about your warning. I cannot reproduce it (4.6.1). ¿Is the casting necessary?
Yeah, I did that with both, and I also forgot to include src/jmalloc.o in the dependency list, for whatever reason.

And I do believe the casting is needed here, yes. I want jmalloc to behave exactly like (a less robust) normal malloc, so it should be called the same way. Indeed, I'm porting it to use in place of normal malloc right now, so yeah.
Topic archived. No new replies allowed.