make questions
Yo, noob here.
Or actually, not noob. Just a noob with make. Very nice, that thing, it's just: I can't get it work with different directories. I once worked with Ant, very nice, but Ant makes problems with the 'sdl-config' script.
I wanna put all my sources into one directory ([...]/src), then the objects ([...]/obj) and the executable in the root dir of the project... I can't get it to work, make makes problems I can solve, and the documentation has huge holes on that topic.
Or maybe I'm just too stupid, who knows...
Anyway, I hope you can help me, and forgive my stupitidy...
Scánkalantesh...
When I had problems with my makefiles several weeks ago, I refered to this thread.
Especially this post.
And all my problems magically dissapeared.
Hope that helps. If not, I could post my own makefile here.
Especially this post.
And all my problems magically dissapeared.
Hope that helps. If not, I could post my own makefile here.
Does this makefile work for you?
Place it in the root directory of your project, which contains subdirs src\ and obj\. This will compile a source file src\test.c, placing the object file in obj\ (obj\test.o), and the executable file in the root directory.
test.exe: obj\test.o gcc -o test.exe obj\test.oobj\test.o: src\test.c gcc -o obj\test.o src\test.c -c
Place it in the root directory of your project, which contains subdirs src\ and obj\. This will compile a source file src\test.c, placing the object file in obj\ (obj\test.o), and the executable file in the root directory.
Sorry, but not really...
I tried that, yeh, but I wanna but them all into one variable... I tried this:
but somehow... I dunno, it doesn't work out
I tried that, yeh, but I wanna but them all into one variable... I tried this:
OBJECTS = main.o game.oSRCDIR = srcOBJDIR = objcolin: $(OBJECTS) $(CC) $(CFLAGS) -o $(OBJDIR)/$(OBJECTS)%.o: %.cpp $(CC) $(CFLAGS) -c -o $(OBJDIR)/$@ $(SRCDIR)/$<
but somehow... I dunno, it doesn't work out
Quote:Original post by FalShen%.o: %.cpp $(CC) $(CFLAGS) -c -o $(OBJDIR)/$@ $(SRCDIR)/$<
but somehow... I dunno, it doesn't work out
Does the base version work?
%.o: %.cpp $(CC) $(CFLAGS) -c -o $@ $<;
yeh, it does... that's what I used until now, but it's a horror when I wanna make bigger projects. I think the problem is in the target for the executable, though.....
You might want to do what most projects do:
1. Create a general-purpose makefile that compiles all sources in current directory.
2. Copy such makefile to each directory.
3. Recursively call makefiles in child directories.
4. Each recursive call will also move compiled .o files to target location (just like VC++ does).
For 1. - refer to the thread I linked.
1. Create a general-purpose makefile that compiles all sources in current directory.
2. Copy such makefile to each directory.
3. Recursively call makefiles in child directories.
4. Each recursive call will also move compiled .o files to target location (just like VC++ does).
For 1. - refer to the thread I linked.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement