You are not logged in.

#1 2017-09-26 20:28:19

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

[SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

Greetings,

I must be missing something obvious, in which case, sorry for the noise. But I am completely stumped on how to put *.o files into a folder called obj without mv *.o obj/. How can I tell make to look in obj/ for the *.o's? Here is the makefile.

CC = g++
CFLAGS = -Wall -g
DEPS = AnimatedProps.h Bullet.h Camera.h Collision.h Config.h \
	Font.h Mouse.h Player.h Shader.h SoundManager.h Weapon.h World.h \
	ResuplySystem.h Ai.h
OBJ = AnimatedProps.o Bullet.o Camera.o Collision.o Config.o \
	Font.o main.o Mouse.o Player.o Shader.o SoundManager.o Weapon.o\
	World.o ResuplySystem.o Ai.o
LD = -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
ODIR = obj

$(ODIR)/%.o: %.c
	$(CC) -c -o $@ $< $(CFLAGS)

johntileengine: $(OBJ)
	$(CC) -o $@ $^ $(CFLAGS) $(LD)

.PHONY: clean

clean:
	rm -f *.o johntileengine

Please note that the following line

$(ODIR)/%.o: %.c 

has no effect on the output.

Tue Sep 26 jbs@dmb-gaming-laptop -> make
g++    -c -o AnimatedProps.o AnimatedProps.cpp
g++    -c -o Bullet.o Bullet.cpp
g++    -c -o Camera.o Camera.cpp
g++    -c -o Collision.o Collision.cpp
g++    -c -o Config.o Config.cpp
g++    -c -o Font.o Font.cpp
g++    -c -o main.o main.cpp
g++    -c -o Mouse.o Mouse.cpp
g++    -c -o Player.o Player.cpp
g++    -c -o Shader.o Shader.cpp
g++    -c -o SoundManager.o SoundManager.cpp
g++    -c -o Weapon.o Weapon.cpp
g++    -c -o World.o World.cpp
g++    -c -o ResuplySystem.o ResuplySystem.cpp
g++    -c -o Ai.o Ai.cpp
g++ -o johntileengine AnimatedProps.o Bullet.o Camera.o Collision.o Config.o Font.o main.o Mouse.o Player.o Shader.o SoundManager.o Weapon.o World.o ResuplySystem.o Ai.o -Wall -g -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
Tue Sep 26 jbs@dmb-gaming-laptop -> ls obj/
Tue Sep 26 jbs@dmb-gaming-laptop -> ls
Ai.cpp             Collision.o       main.o             Shader.cpp
Ai.o               Config.cpp        Makefile           Shader.o
AnimatedProps.cpp  Config.o          Mouse.cpp          SoundManager.cpp
AnimatedProps.o    ControlPoint.cpp  Mouse.o            SoundManager.o
Bullet.cpp         Font.cpp          obj                Weapon.cpp
Bullet.o           Font.o            Player.cpp         Weapon.o
Camera.cpp         include           Player.o           World.cpp
Camera.o           johntileengine    ResuplySystem.cpp  World.o
Collision.cpp      main.cpp          ResuplySystem.o
Tue Sep 26 jbs@dmb-gaming-laptop -> 

As we can see obj/ is empty and *.o's are populating my source directory. What am I missing? Thanks!

Last edited by JohnBobSmith (2018-01-27 20:59:01)


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#2 2017-09-26 20:49:48

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

By using GNU Autotools? big_smile

...just kidding! smile Oh man, I'm excited to try out your new project! If only my Ryzen CPU would hurry up and come in the mail. sad

I'll look at the Makefile / obj directory issue when I get a chance, but I have a feeling someone else will be able to help before me. wink FYI, a Google search for "add object directory to makefile" turned up a few StackOverflow results, but it looks like yours should be working!

Offline

#3 2017-09-26 20:56:07

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,534
Website

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

Make is using implicit rules as you never ask it to build anything like "obj/AnimatedProps.o".

Building "johntileengine" however has a dependency on "AnimatedProps.o" (note, no leading directory).  So make looks for that object file, when it doesn't find it, it looks for a rule to build "AnimatedProps.o" but you didn't provide any such rule so it falls back to the implicit rule of building the .o file from an source file with the same basename.

Note that your ODIR rule only tells make how to make files like "obj/AnimatedProps.o" when they are needed, it doesn't actually direct it to try to make them - and as nothing else lists those files as a dependency, that rule never does anything.

One solution would be to expand the OBJ variable to prepend "obj/" to each item.  That way the dependency on $(OBJ) will expand to files like "obj/AnimatedProps.o" and your explicit rule will be called.

Also, please don't us CC for a C++ compiler, CC is for C compiler.  Use CXX for a C++ compiler.

Last edited by Trilby (2017-09-26 21:07:01)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#4 2017-09-26 21:07:10

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

Here's the updated and still non-working makefile:

CXX = g++
CXXFLAGS = -Wall -g
DEPS = AnimatedProps.h Bullet.h Camera.h Collision.h Config.h \
	Font.h Mouse.h Player.h Shader.h SoundManager.h Weapon.h World.h \
	ResuplySystem.h Ai.h
OBJ = AnimatedProps.o Bullet.o Camera.o Collision.o Config.o \
	Font.o main.o Mouse.o Player.o Shader.o SoundManager.o Weapon.o\
	World.o ResuplySystem.o Ai.o
LD = -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
ODIR = obj

$(ODIR)/%.o: %.c
	$(CXX) -c $< -o $@

johntileengine: $(OBJ)
	$(CXX) -o $@ $^ $(CXXFLAGS) $(LD)

.PHONY: clean

clean:
	rm -f *.o johntileengine

I'll take a moment to understand your post Trilby. Thanks! smile
EDIT: So the following only generates errors:

OBJ = obj/AnimatedProps.o obj/Bullet.o obj/Camera.o obj/Collision.o obj/Config.o \
	obj/Font.o obj/main.o obj/Mouse.o obj/Player.o obj/Shader.o obj/SoundManager.o \
	obj/Weapon.o obj/World.o obj/ResuplySystem.o obj/Ai.o
Tue Sep 26 jbs@dmb-gaming-laptop -> make
make: *** No rule to make target 'obj/AnimatedProps.o', needed by 'johntileengine'.  Stop.
Tue Sep 26 jbs@dmb-gaming-laptop -> 

My brain is completely fried. One would hope that such a simple task (putting O files in obj/) shouldn't be this difficult. Obligatory break for minimum of two hours. Be back then! smile

Last edited by JohnBobSmith (2017-09-26 21:15:00)


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#5 2017-09-26 21:14:52

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,534
Website

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

johntileengine: $(OBJ:%=obj/%)

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#6 2017-09-26 22:23:33

edacval
Member
From: .LT
Registered: 2008-10-23
Posts: 91

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

Deleted, misread question.

Last edited by edacval (2017-09-26 23:18:52)

Offline

#7 2017-09-26 22:31:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,534
Website

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

edavcal, that will not help, the problem is not in failing to find source files for that recipe, it's that that recipe is never invoked.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#8 2017-09-26 23:58:55

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

Alright so I'm back at it after a good walk to clear the head. The most recent makefile:

CXX = g++
CXXFLAGS = -Wall -g
DEPS = AnimatedProps.h Bullet.h Camera.h Collision.h Config.h \
	Font.h Mouse.h Player.h Shader.h SoundManager.h Weapon.h World.h \
	ResuplySystem.h Ai.h
OBJ = AnimatedProps.o Bullet.o Camera.o Collision.o Config.o \
	Font.o main.o Mouse.o Player.o Shader.o SoundManager.o \
	Weapon.o World.o ResuplySystem.o Ai.o
LD = -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
ODIR = obj

$(ODIR)/%.o: %.c
	$(CXX) -c $< -o $@

johntileengine: $(OBJ:%=obj/%)
	$(CXX) -o $@ $^ $(CXXFLAGS) $(LD)

.PHONY: clean

clean:
	rm -f *.o johntileengine

note this line:

johntileengine: $(OBJ:%=obj/%)

fails to work:

Tue Sep 26 jbs@dmb-gaming-laptop -> make
make: *** No rule to make target 'obj/AnimatedProps.o', needed by 'johntileengine'.  Stop.
Tue Sep 26 jbs@dmb-gaming-laptop -> 

This is some progress, as obj/ is now pre-pended to AnimatedProps.o. Between these errors and Trilby's helpful first reply, I have some ideas that im going to work on. I'll post any progress (or not) that I make.


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#9 2017-09-27 00:23:31

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,534
Website

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

I guess that expansion will not work.  Why not just use VPATH:

...
ODIR = obj
VPATH = obj

%.o: %.c
        $(CXX) -c $< -o $(ODIR)/$@

johntileengine: $(OBJ)
        $(CXX) -o $@ $^ $(CXXFLAGS) $(LD)

Also, I'm confused now about the type of code: your Makefile only references .c files, but you are using a C++ compiler.  I suggested before to use CXX as the variable for a C++ compiler, but why are you even using that at all?  Is this C code or C++ code?

(Also, what is DEPS for?)

Last edited by Trilby (2017-09-27 00:24:13)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#10 2017-09-27 02:53:31

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

Sorry for the confusion. This is C++ code. The project this Makefile is used for can be found here: https://github.com/JohnBobSmith/john_tile_engine For the %.c, I'm guessing I need to use %.cpp instead of %.c? DEPS was what remains when I was trying to get make to recompile header files if they changed. For instance if you have in SomeHeader.h int theInt = 5, changing it to theInt = -1 wouldn't trigger a recompile of SomeHeader.h, even though it should, unless I'm mistaken. In the current Makefile that can be omitted completely. Now, none of my ideas worked, but I will test your idea Trilby and get back to you.  After testing Trilby's idea, here is the current Makefile:

CXX = g++
CXXFLAGS = -Wall -g
OBJ = AnimatedProps.o Bullet.o Camera.o Collision.o Config.o \
	Font.o main.o Mouse.o Player.o Shader.o SoundManager.o \
	Weapon.o World.o ResuplySystem.o Ai.o
LD = -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
ODIR = obj
VPATH = obj
	
%.o: %.c
	$(CXX) -c $< -o $(ODIR)/$@

johntileengine: $(OBJ)
	$(CXX) -o $@ $^ $(CXXFLAGS) $(LD)

.PHONY: clean

clean:
	rm -f *.o johntileengine

We're getting close to finding a solution that will hopefully benefit those who come after me, asking a similar question. Once we but this problem to bed, I'll have a very nice Makefile for small projects. I'll keep us posted. smile

EDIT: Ack! No go! It looks like I'm going to have to sleep on this one. Trilby's latest suggestion didnt work. Everything compiles, the obj/ dir is created, but the *.o files still populate my source directory. Output: https://gist.github.com/JohnBobSmith/81 … c92d65ca97

I have also updated the post to include the very most recent Makefile.

Last edited by JohnBobSmith (2017-09-27 03:01:42)


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#11 2017-09-27 11:49:29

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,534
Website

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

JohnBobSmith wrote:

This is C++ code... For the %.c, I'm guessing I need to use %.cpp instead of %.c?

*headdesk*, yes.  So as is your build rules isn't doing anything at all, make is just using it's built in implicit rule.

DEPS was what remains when I was trying to get make to recompile header files if they changed. For instance if you have in SomeHeader.h int theInt = 5, changing it to theInt = -1 wouldn't trigger a recompile...

You can have multiple requirements for an object file, a varation of `%.o: %.cpp %.hpp` if every cpp file has an associated hpp file.  There are good reasons to do this when a header actually does change, but why are you setting values in headers, that generally shouldn't be done: declare "theInt" in the header file, set it in the source file.

Now, none of my ideas worked

You seem to be reinventing many wheels (and making them square).  Have you read any Makefile documentation?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#12 2017-09-27 16:25:21

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

I hate to admit but I've been following random tutorials like this instead of reading the documentation  *faceplant* . I really don't understand what I'm doing or why. Hence all the square wheel reinventing. So I'll have to learn, or be left with the natural consequence of a Makefile that doesn't work the way I need it to. Outside of man pages is there any particular documentation I should be looking at? Thanks for your continued help with this matter Trilby. smile


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#13 2017-09-27 16:35:07

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,534
Website

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

JohnBobSmith wrote:

I hate to admit but I've been following random tutorials like this instead of reading the documentation

There's nothing wrong with that.  That seems a perfectly good tutorial that lives up to it's name.  But it's name is "a simple makefile tutorial."  If you just want something simple that'd do, but you are trying to do somewhat more complex things with your makefile.

As to what else to read, if you are ok with gnu-specific extensions, the gnu-make documentation is phenomenal.

Also read lots of Makefiles from reliable sources to pick up on some of the de-facto standards.  Sticking to these are useful as others would know where to look for something in your Makefile and/or how to modify it as needed for their system.

Last edited by Trilby (2017-09-27 16:36:48)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#14 2017-09-27 17:53:07

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

Sounds good! It looks like I have some homework to do. Ill take some time to read up on my documentation. I have some ideas (like using patsubst) that I need to try. I'll update this thread in a few days time (or less if I find the solution before then) with my results. smile


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#15 2017-09-27 18:33:43

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,534
Website

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

Can I ask *why* you would want to put the object files in their own directory?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#16 2017-09-28 00:18:01

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

A couple of reasons. First, I like to keep my source directory clean, as I find myself adding and removing files regularly. Not having O files everywhere makes tab completion quicker since there is only one option instead of two (*.cpp or *.o). Second, during my time with Code::Blocks I really liked having O files in a separate directory. Having them in their own directory just makes a lot of sense to me. Other than that, its really not a big deal. If I can't find a solution I'll manage without. Having O files in a separate directory just seems more... Organized? Professional? Perhaps my mild OCD is a factor in this too. I like keeping things clean, neat, and organized. smile

I've got a really, REALLY dirty hack incoming which if it works, great and I'll update this thread. If not, I'll keep searching for a solution.


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#17 2017-09-28 00:22:55

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

Well, out-of-tree build directories are a thing, apparently.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#18 2017-09-28 00:40:00

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

My hack failed so for now it looks like I make do without *.o in a separate build/ or obj/ dir... I'm done troubleshooting this issue. For now at least. I just cannot for the life of me believe that something so seemingly trivial is so hard to get working... Oh well. Sucks to be me I guess. sad


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#19 2017-09-28 00:41:39

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,534
Website

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

JohnBobSmith wrote:

Not having O files everywhere makes tab completion quicker...

Ah ... I'd say not having the source files there makes it quicker! tongue

It is far more common to keep the source files somewhere else (like src/) and this is much easier handled in Makefiles simply by using VPATH.

As for looking professional ... to whom?  You'll never distribute .o files, that would not look "professional" regardless of where they were stashed, so you `make clean` before you `make dist` or `make tarball`, and .o files should be on any vcs's ignore list.

Eschwartz, out of tree builds are common ... with cmake.  I don't know of many examples with make (actually I've never seen any, but I'm sure they do exist somewhere).  With cmake in the C++ world you'd also not have a obj/ directory, just a build/ where *everything* that is built goes.  In the make and C world it's far more common for (top-level) build products to be placed in the top level directory where the Makefile is - but source files will generally be in a subdirectory.

Neither one of these is right or wrong, but JBS, you'll almost certainly find it easiest to swim with the current ... so pick the river with the current that most suits you.  Trying to get make to behave like cmake can work, but it will be a PITA, use make like make, or just use cmake.

Last edited by Trilby (2017-09-28 00:46:30)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#20 2017-09-28 00:52:48

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

Out-of-tree builds are also common with meson tongue and apparently "modern build systems" are trending in that direction. Point being, that users who want an obj/ directory might be inspired by the out-of-tree builds mindset...

But make has a perfectly suitable VPATH which shouldn't require that much struggling I don't think.
(Autotools gives you VPATH for free.)


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#21 2017-09-28 01:35:46

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,534
Website

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

Eschwartz wrote:

(Autotools gives you VPATH for free.)

Err... yeah.  Like buying a Ferrari gives you a rear-view mirror for free. tongue


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#22 2017-09-28 02:18:37

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

No argument here!


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#23 2017-09-28 16:45:49

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

After some thought, my final decision is that its not that big of a deal to have *.o files in their own dir. A very big part of me is devastated that I couldnt get this feature working. But I have more important things to do, like actually developing my project, than to worry about having "the perfect makefile". Perfection is guaranteed to cause feelings of disappointment and failure. Not good for the mixed mood state I find myself in. Therefore, because my makefile does indeed compile, that will have to be good enough, even though a large portion of me is very upset that I couldnt get this feature (*.o files in their own dir) working.

This isn't solved, we havent found a workaround, so I wont mark this thread as anything special. But feel free to let this thread die as it has run its course. Thanks to everyone for all your input and insights as to what was going on! If I find myself working on this again in the future I will revive this thread and we will go from there. Peace out! smile


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#24 2017-09-28 17:24:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,534
Website

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

FWIW, this works fine here:

PROG  = whatever
OBJS  = one.o two.o
ODIR  = obj

all: $(PROG)

%.o: %.c
	gcc -c -o $(ODIR)/$@ $<

$(PROG): $(OBJS)
	cd obj; gcc -o ../$(PROG) $^

Last edited by Trilby (2017-09-28 17:25:34)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Online

#25 2017-09-28 18:46:24

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: [SOLVED] (again) - Stumped on getting Makefile to look for *.o in obj/

Holy crap that is awesome! It looks like I shouldnt have thrown in the towel so soon! We have two problems with this however. #1, you must manually create the obj/ dir. No amount of

if [ ! -d obj ]; then mkdir obj; fi

anywhere in the makefile works. This is not a big deal at all. However, issue #2 is. The second issue is that every invocation of make re-compiles everything, even if it doesn't need to be recompiled. I found this quote from here:  https://stackoverflow.com/questions/173 … y-time-why

StackOverflow wrote:

Your targets are all not real files. Make them the names of the actual files you're generating so that make can find them and check timestamps.

Unfortunately I dont know what this means. The target is the left side of the semicolon, so how does one make it the actual files...? If we can prevent make from recompiling everything every single time, this is exactly what I was looking for!

The most recent makefile with my necessary modifications:

CXX = g++
CXXFLAGS = -Wall -g
PROG  = johntileengine
OBJS = AnimatedProps.o Bullet.o Camera.o Collision.o Config.o \
	Font.o main.o Mouse.o Player.o Shader.o SoundManager.o \
	Weapon.o World.o ResuplySystem.o Ai.o
ODIR  = obj
LD = -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio

all: $(PROG)

%.o: %.cpp
	$(CXX) -c -o $(ODIR)/$@ $<

$(PROG): $(OBJS)
	cd obj; $(CXX) -o ../$(PROG) $^ $(CXXFLAGS) $(LD)

clean:
	rm -rf $(PROG) $(ODIR) 

With this new find im now more determined than ever to find a working solution. I'll test some things and get back to you! smile


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

Board footer

Powered by FluxBB