Advertisement

Multiple source compilation, C++ docs

Started by February 05, 2001 10:12 PM
1 comment, last by AndyMan 23 years, 11 months ago
If you know about DJGPP and can bear teaching a fool (like my friends at uni had to) I never learnt how to efficiently manage large source code in multiple files, and I can''t work out how it should be done. Here''s how things go at the moment. I have a file includes.C that looks like this (execpt these are just a fraction of the lines, it''s actually a lot more): #include #include #include using namespace std; #include "allegro.h" #include "palettes.C" #include "window2.C" #include "shapes2.C" #include "main.C" I have about 60 .C files in my program, coming to a total of 180kB. Here''s my compile.bat: gxx includes.C -w -o game.exe -lalleg So you can see how all of my code if treated like one file. It was only taking about 10 seconds to compile when it was around 200kB, but I found some C++ tricks to make my code cleaner and shorter, but also longer to compile. It now takes half a minute, which is too much for me. I read some stuff about compiling the source files separately with -c to make .o files and them compile them all together. I thought I''d try to get that working manually and then get RHIDE to create the makefile for me, but many of my .C files are heavily dependent on what has gone before. Does this mean that I have to copy everything I''ve written except the function implementations into .h files to be #included by everyone? I don''t really want to go through my 180kB of code making big .h files. If I do, who #includes what? How do you stop the compiler complaining about multiple definitions? Trouble with multiple definitions earlier led me to my current position, with effectively only one long source file. As you can see, I was never formally taught any C/C++. I got the C library docs from the DJGPP site, but where can I get all the C++ standard library docs? I didn''t know vectors etc existed until a month ago, and for all the files that have ended up in \lang\cxx\ I have no knowledge of how to use them.
Try using some pre-compiler directives to stop the multiple definitions errors. Lets say you have a file call VectorMath.h, do something like this in your include file,

#ifndef VECTORMATH_INCLUDED
#define VECTORMATH_INCLUDED

#include"VectorMath.h"
#endif

This will stop the compiler from including the file if it can already see it from somewhere else. You can put those lines around an entire header file definition too.

#ifndef VECTORMATH_INCLUDED
#define VECTORMATH_INCLUDED

/*...All the code for VectorMath.h goes here...*/
#endif

Thats just anohter way to do it. I guess I haven''t really used RHIDE of DJGPP for that matter. I''ve found Visual C++ to be excellent for managing multiple source projects though. Its something to look at for sure.
BTW. 60 files seems like kind of a lot! =)
Advertisement
Maybe it wasn''t such a good idea to do it in 60 files. But there is 180kB of code with 50 different classes implemented.

So who else has a project with heaps of code and knows how to manage it all? How do you compile it?

I''m sure lots of you are C++ programmers doing big projects. Anyone?

This topic is closed to new replies.

Advertisement