Advertisement

Strange GCC Issue

Started by November 07, 2005 05:08 AM
3 comments, last by grady 18 years, 10 months ago
I've always had a very strange issue with my C++ code (I come from a Java background, just so you know). I'm using GCC and a run-of-the-mill make file for compiling. Suppose I have a large project composed of a number of Classes and also some procedual C code in the mix too. It all compiles and links fine, no problems. Now, pretend I go back to one of my classes and add in or remove some member variables or add, remove or change function prototypes. I then recompile and relink these classes and run the prog. It will mostly likely segfault or strange things will happen. I get around this issue recompiling ALL my C code. Now, whilst this isn't preventing me from continuing my project, I've always found it a little strange that I need to do this. Anyone familiar with this issue or know what I might be doing wrong? Or is it just "C thing"? :)
Parallel RealitiesProject: Starfighter
You're probably not setting up dependencies in your make files properly. Best I can say is to use an IDE (code::blocks is nice) that handles that for you, or read up on makefiles and how c files get linked together (to figure what depends on what) a bit more (it's possible to add stuff to make it setup dependences automatically but it's tricky and I'm not at my linux box). What most likely happened is you didn't recompile the files that included your modified class.
Advertisement
hehe... looks like I'm stuffed then, since I have a huge header file that includes pretty much all my classes. I couldn't be bothered to pick and choose what should be in each individual header so I just include the lot ;)

That's cleared up my problem though. Cheers :)
Parallel RealitiesProject: Starfighter
You can still setup the dependency stuff. But you wont gain much until you use just the needed headers in your files (and maybe use precompiled headers for rarely changed headers). Using an IDE is the easiest solution in my opionion. Makefiles can work by having the compiler determine dependencys but it's rather tricky to setup. But when your done you just run make all (or what ever you use for all) and it only recompiles what's needed.
I'm not an expert, but this is what I do to automatically create a makefile for my small projects. The file below would be called game.mk. The line in the 'makefile' target that calls the compiler with the -M option does all of the magic. 'gcc -M source.cpp' will barf a makefile-syntax-friendly list of header files that source.cpp depends on. I found this out from O'Reilly's "Managing Projects with Make" book.

#to recreate the makefile type 'make -f game.mk makefile AUTO=headers'INCLUDE=-I /usr/incl(truncated)SOURCES=$(OBJS:.o=.cpp) terrain.cppgame : $(OBJS)        $(CXX) $(OBJS) $(INCLUDE) $(LIBS) -pg -o $@terrain : $(TERRAINOBJS)        $(CXX) $(TERRAINOBJS) $(INCLUDE) $(LIBS) -pg -o $@clean:        rm core* *.o gamemakefile : $(AUTO)        cp game.mk $@        $(CXX) $(INCLUDE) -M $(SOURCES) >> $@headers:
----------------------------www.physicsforums.comwww.opengl.org

This topic is closed to new replies.

Advertisement