Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Maeriden

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

Topics I've Started

Subdirectories in makefile

29 January 2013 - 08:50 AM

In an effort to try to learn makefiles I wrote this
 

C = $(CXX)
CFLAGS = -g -Wall -Wextra -I$(SRC_DIR) -std=c++0x

SRC_DIR = src
BIN_DIR = bin
OBJ_DIR = obj

vpath %.cpp $(SRC_DIR)
vpath %.h $(SRC_DIR)
vpath %.o $(OBJ_DIR)

GPATH = src obj

SRC = main.cpp resources.cpp ui.cpp
OBJ = $(SRC:.cpp=.o)

.PHONY: clean all

all: $(OBJ)
    $C -o $(BIN_DIR)/exe $^


main.o: main.cpp defaults.h
    $C -c $< -o $(OBJ_DIR)/$@ $(CFLAGS)

resources.o: resources.cpp resources.h
    $C -c $< -o $(OBJ_DIR)/$@ $(CFLAGS)

ui.o: ui.cpp ui.h defaults.h
    $C -c $< -o $(OBJ_DIR)/$@ $(CFLAGS)


clean:
    rm -f $(OBJ_DIR)/*.o


When I run make and the obj directory is empty it compiles all the .cpp files and places them in $(OBJ_DIR)/$@ -> obj/file.o

However when it is time to execute the all target, g++ doesn't find .o files, because $^ contains only the files without the directory prepended

According to http://www.gnu.org/software/make/manual/make.html#Search-Algorithm this is the intended behavior (though not what I want at all) and it says I can modify it using the GPATH variable, which I set but seems to be ignored by make

Notes: if I run make again it finds the files in the obj directory, and since they don't need to be recompiled the path is preserved, so I can't even modify all to be

$C -o $(BIN_DIR)/exe $(addprefix $(OBJ_DIR)/$^)

A first invocation of make would build and link the files correctly, but the second time it would try to link obj/obj/file.o and fail



What am I doing wrong?


Segmentation fault in call to SDL_Quit

27 November 2012 - 09:53 PM

I noticed it just recently, as I've been writing quite a bit without debugging. What is weird is that it didn't use to happen before (or maybe I just never noticed? But it seems unlikely...). So after hours of trying to see if I screwed up somewhere I decided to make a simple test program
[source lang="cpp"]#include <SDL.h>#include <iostream>#undef main // To use standard outputint main ( int argc, char** argv ){ if(SDL_Init(SDL_INIT_VIDEO) < 0) { std::cout << "Unable to init SDL: " << SDL_GetError(); return 1; } SDL_Surface* screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE); if (!screen ) { std::cout << "Unable to set 640x480 video: " << SDL_GetError(); return 1; } SDL_Quit(); // Error here return 0;}[/source]
Running gdb from codeblocks shows me 4 sigsegv before the debugger shuts down. This is the call stack for the first one (in the others the addresses of unknow functions change). Sometimes it stops at EndTask and sometimes at lstrlenA

#0 76D27CDA USER32!EndTask() (C:\Windows\syswow64\user32.dll:??)
#1 00000000 0x01967979 in ??() (??:??)
#2 00000000 0x0028fdc4 in ??() (??:??)
#3 1000D676 HydraDMH!HookMessages() (C:\Program Files (x86)\ATI Technologies\HydraVision\HydraDMH.dll:??)
#4 00000000 0x00360820 in ??() (??:??)
#5 00000000 0x00000000 in ??() (??:??)


#0 76E0AD97 lstrlenA() (C:\Windows\syswow64\KernelBase.dll:??)
#1 00000000 0x385f24bb in ??() (??:??)
#2 00000000 0x00000100 in ??() (??:??)
#3 00000000 0x40380000 in ??() (??:??)
#4 76D27C95 USER32!EndTask() (C:\Windows\syswow64\user32.dll:??)
#5 00000000 0x0028f938 in ??() (??:??)
#6 76D27CEC USER32!EndTask() (C:\Windows\syswow64\user32.dll:??)
#7 00000000 0x40380000 in ??() (??:??)
#8 00000000 0x383353d9 in ??() (??:??)
#9 00000000 0x0028fdc4 in ??() (??:??)
#10 1000D676 HydraDMH!HookMessages() (C:\Program Files (x86)\ATI Technologies\HydraVision\HydraDMH.dll:??)
#11 00000000 0x00230848 in ??() (??:??)
#12 00000000 0x0028f9b4 in ??() (??:??)
#13 00000000 0x00000000 in ??() (??:??)

I have no idea of what to do. My skills in debugging are also close to 0. Can anyone help please?

Debugger stopping at asISciptModule::Build()

04 October 2012 - 02:52 PM

Well, the issue is pretty simple: I'm trying to debug my code and when the debugger hits the call to module->Build() first the program closes itself, then the debugger stops itself too, with the message "The program is not being executed"

I'm still a real novice when it comes to debugging, and I started trying out AS only recently, so I'm wondering if there's anyone who can help me understand what's going on. I'm using C::B 10.05 and its debugger (which I believe is called DBG?).
I'm not posting info right now since I have no idea what could be relevan to the problem.

Strange behaviour of pointers to derived class

28 June 2012 - 07:20 PM

I am trying to make a game states system.
I made a virtual base class 'GameState' and derive the various states from it. The states are pushed in a std::vector<GameState*>

At first I declared the class holding the vector, the GameState base class, and derived states classes all in the same header and implemented them in the same source file, and everything was ok. There is a function called by the states that changes the current state

[source lang="cpp"]void ChangeState(GameState* newstate)[/source]

Then I decided to put each class in a separate header-source and the problem appeared.
If i try to pass to it, say, a pointer to an instance of class PlayState (derived from GameState) the compiler gives the following error

[source lang="cpp"]game->ChangeState(game->play_state)[/source]

error: no matching function for call to 'GameManager::ChangeState(PlayState*&)'
note: candidates are: void GameManager::ChangeState(GameState*)


'game' is a pointer to GameManager that every state has
GameManager holds the vector and pointers to states' instances (like play_state).

Trying random stuff, I noticed that if I include the headers of each derived state in GameManager.h (instead of GameManager.cpp) the problem gets fixed (at first I just forward declared the classes since GameManager holds only pointers).

I'd like help in understanding what's going on. Sorry if the explanation isn't very clear but I have trouble identifying the issue myself and I didn't want fill the post with all the headers (I'll do it if it's necessary though)

PARTNERS