Jump to content

  • Log In with Google      Sign In   
  • Create Account


Maeriden

Member Since 02 May 2012
Offline Last Active Jun 27 2013 10:38 PM

Posts I've Made

In Topic: Subdirectories in makefile

03 February 2013 - 09:54 AM

I know. It just didn't seem a smart solution so I looked for something else


In Topic: Subdirectories in makefile

01 February 2013 - 04:16 PM

Mmm it's not very different from mine. To get around the issue of directories the target objects are written directly with obj/ prepended.
I wanted to avoid this solution because I didn't understand how to make make (no pun) work out the headers dependencies with a rule like $(OBJECTS): obj/%.o : src/%.cpp and thus decided to write a rule for each .o to avoid recompiling the whole project. Doing so meant that I had to manually write the directory variable in each rule, which seemed kind of dumb.

From the informations I was able to gather (I couldn't find an example that explained problems with GPATH) it looks like the solutions are: writing the path manually for each rule, using the general rule and have all the sources recompiled every time an header changes, or learning to use .d files (which will wait since I got fed up with make for a while).
Or use a different make system.

Thank you all for your advice, I really apreciate it :)

In Topic: Subdirectories in makefile

29 January 2013 - 06:12 PM

 Why do you need you .o files in a separate folder? If you do "rm -f $(OBJ)" it will clean them all up anyway.

Well, I don't actually plan on cleaning the .o files very often, and I prefer not to keep them in the project root directory

 Also, I dont know if you care, but I personally try to keep away from GNU extensions so that it works with different make tools (i.e BSD make).

I don't specifically need to write a file that works with other tools, but I suppose it would be better to learn how to do it. Which extensions did I use?

 You also dont need this bit, you can just make a rule to generate .o files from .cpp (this is the main reason for make) An example of such a rule would be ".cpp.o:".

I've been wondering about this kind of rules. I've seen "$(OBJ): %.o: %.cpp" (here) but I can't understand how that would handle recompilation in the case a header file included by the source is modified

 

Thanks for the offer, but I've already seen quite a bit of examples. What I need is someone who would explain them


In Topic: Subdirectories in makefile

29 January 2013 - 01:31 PM

That's what I thought at the beginning (see the note). In that case if any .o is not found it gets built in $(OBJ_DIR), then make links files in $(OBJ_DIR) and makes me happy. But every time that a file does NOT need to be rebuilt, the path where make finds it is remembered (so main.o becomes obj/main.o) when used both as target and dependency. Proceeding to the link command it becomes g++ -o bin/exe obj/obj/main.o

 

What really makes my head hurt is why make ignores GPATH. I wouldn't have any problem if only that worked


In Topic: Strange behaviour of pointers to derived class

28 June 2012 - 08:59 PM

My guess is that when you are not including all the headers, you are using forward class declarations, and at the point of the error the compiler doesn't know that PlayState derives from GameState.

Ideally the vast majority of your code shouldn't know anything at all about the derived classes, so instead of

game->ChangeState(game->play_state);
you can have something like
game->ChangeState(game_state_vector[PLAY_STATE]);
where `PLAY_STATE' is a value in an enum and `game_state_vector' is the vector of pointers to GameState that you described.

Would something like that work?

That doesn't really work because the states are not already in the vector, ChangeState() pushes them into it (honestly I would have used a different system which doesn't involve a vector at all, but the tutorials on internet say to do it like this, and supposedly they know better than me, so...)

But I think you nailed the problem! In the implementation file for each state I didn't include the header of the other state that was being passed to ChangeState(), so I guess it couldn't see that it was derived from GameState, it would see it as a, say, PlayState pointer because it is declared like that in GameManager.h.
Including the states headers in GameManager.h made it work because then each state header, by including GameManager.h, would have included the other states headers as well

Thank you very much

Sounds right. Except where not possible, or as a way of API protection, you want to include the class headers that you have pointers to. In this case you need to include PlayState.h, which should define PlayState, when you're using a PlayState pointer.

I'll keep that in mind.
Since in the source file where ChangeState() is defined the states headers are included, and it is the same file where the states are instantiated, ChangeState() knows that they are derived and I thought it was enough to make it work.

PARTNERS