Jump to content
  • Advertisement
Sign in to follow this  
FalShen

make questions

This topic is 4390 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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...

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Does this makefile work for you?


test.exe: obj\test.o
gcc -o test.exe obj\test.o

obj\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.

Share this post


Link to post
Share on other sites
Sorry, but not really...
I tried that, yeh, but I wanna but them all into one variable... I tried this:

OBJECTS = main.o game.o
SRCDIR = src
OBJDIR = obj

colin: $(OBJECTS)
$(CC) $(CFLAGS) -o $(OBJDIR)/$(OBJECTS)

%.o: %.cpp
$(CC) $(CFLAGS) -c -o $(OBJDIR)/$@ $(SRCDIR)/$<


but somehow... I dunno, it doesn't work out

Share this post


Link to post
Share on other sites
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 $@ $<;

Share this post


Link to post
Share on other sites
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.....

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Well... that could be the problem... It is looking for the file in the root directory, isn't it? How can I solve that?
with
%.o: $(SRCDIR)/%.cpp

maybe?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!