Sign in to follow this  

Makefiles: processing multiple object files

This topic is 2959 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

Hi: It has actually been a while since I don't code any C++ since my professional life has shifted towards web development... Really, php and javascript code can actually make you forget how to use the old C++! Anyway, still I try to code some C++ in my spare time, for the sake of learning - still an absolute beginner here - and for my own pleasure. Recently I came up with a little problem with my makefiles... Say that I have separate source and header files that accomplish isolate tasks. I am using the SDL library: -screen.cpp, for my screen related functions, encapsulated within a class. -functions.cpp, for miscellaneous static functions (just for the sake of having them within a class). My makefile could go like this:
result: objects/screen.o objects/functions.o sources/main.cpp
	g++ -Wno-deprecated -o resultado sources/main.cpp objects/screen.o objetos/functions.o -lSDL

#Screen...
objects/screen.o: sources/screen.cpp headers/screen.h
	g++ -Wno-deprecated -c -o objects/screen.o sources/screen.cpp -lSDL

#Functions
objects/functions.o: sources/functions.cpp headers/functions.h
	g++ -Wno-deprecated -c -o objects/functions.o sources/functions.cpp -lSDL



So, my main result would depend on both screen.o and functions.o. Say that it is absolutely predictable that my program would grow with a... camera, for example. Still related to graphics, but something I would like to stand on its own.. My makefile then:
result: objects/screen.o objects/functions.o objects/camera.o sources/main.cpp
	g++ -Wno-deprecated -o resultado sources/main.cpp objects/screen.o objects/camera.o objects/functions.o -lSDL

#Camera...
objects/camera.o: sources/camera.cpp headers/camera.h
	g++ -Wno-deprecated -c -o objects/camera.o sources/camera.cpp -lSDL

#Screen...
objects/screen.o: sources/screen.cpp headers/screen.h
	g++ -Wno-deprecated -c -o objects/screen.o sources/screen.cpp -lSDL

#Functions
objects/functions.o: sources/functions.cpp headers/functions.h
	g++ -Wno-deprecated -c -o objetos/functions.o sources/functions.cpp -lSDL



Say then that my program keeps on growing on the graphics until I have like ten separate headers... My "result" file should depend and link against lots of object files. My program could also grow on other respects, like, for example, multiple structures that I should use, each one on its own source file but all related. The most obvious example is different kinds of classes contained within a simple video game: all related to the "game" but "apart" from the graphics... That should make my "result" file link against a whole lot more of object files!. For the sake of making it manageable I was wondering if I could, somehow, take all the "graphic" object files and put them together in a single "group_graphics.o". Same with all the "game" objects: all within a single "map_related.o" file. I know that I could just g++ them together into a single object from their sources but, is there something I can do with their objects?. I am aware that, from the point of view of the makefile, it makes no difference at all since a single change in a source and my hipotetical "all_in_one.o" file has to be processed again but still I cannot but think that I could manage my work better if I could do as I ask. Frankly, I am not sure if my question makes sense at all from the point of view of the veteran coder but I will appreciate all answers and suggestions. Thanks a lot in advance.

Share this post


Link to post
Share on other sites

This topic is 2959 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this