0

So here's what's happening:

In the beginning, there was one main source file. It compiled in a few seconds, but it was ~1000 lines long, so I began to split it into separate .h/.cpp combinations. The good news was that my main source's length is now ~500 lines, but the bad news is that I can't completely compile/link it.

So I've been at it for a while, but it hasn't gotten any better.

Here's an overview (or no overview):

There are four source files:

  • corbit.cpp (main),

  • initialization.cpp (initialize vector of entities),

  • entity.cpp (entity class file),

  • display.cpp (HUD and camera class file).

Main includes all other source files, as "display.h". Also, (for example) allegro.h.

display.cpp includes "entity.h" (with the #ifndef ENTITY_H guard thing), and "display.h", as well as (for example) allegro.h

entity.cpp includes "entity.h"

initialization.cpp includes (again with the #ifndef guard) "entity.h", as well as "initialization.h"

When I hit compile in Codeblocks, using GCC, it opens up locale_facets.tcc (anyone know what that is?) as an empty file. It also gives me two error messages, as follows:

  • corbit.o In function 'ZNSt6vectorIP10physical_tSaIS1_EE5clearEv'

  • display.o: [project directory]..\lib\gcc\mingw32\3.4.5........\include\c++\3.4.5\bits\locale_facets.tcc (line 2497) (first defined here) <-- highlighted red

and

  • corbit.o In function 'ZNSt6vectorIP10physical_tSaIS1_EE5clearEv'

  • display.o: [project directory]..\lib\gcc\mingw32\3.4.5........\include\c++\3.4.5\bits\locale_facets.tcc (line 2497) (first defined here) <-- highlighted red

, which look identical. In my main I have declared

std::vector<physical_t*> entity;

(physical_t is the entity class), which might have something to do with the first message.

In each .h file I have

#ifndef FILENAME_H
#define FILENAME_H
[declarations]
#endif

And whenever I include a header that doesn't correspond with the .cpp file I'm including it in, I enclose it in

#ifndef FILENAME_H
#include "filename.h"
#endif

I do have different .cpp files including iostream, math.h, allegro.h, and things like that, so that the functions they are defining can compile without syntax errors.

Using Windows, codeblocks, gcc. I can't think of anything else. Help would be appreciated!

Jesse Good
  • 50,901
  • 14
  • 124
  • 166
pmelanson
  • 330
  • 4
  • 16
  • there are actually angle brackets around physical_t*, but I can't figure out how to do those in stack overflow – pmelanson Jun 11 '12 at 01:53
  • Though I'm not certain of it, my immediate guess is that it will probably be easier to fix this starting from the one big file that works, rather than the already-split, but no longer working files you've posted. – Jerry Coffin Jun 11 '12 at 03:19
  • Coincedentally, I just gave up and started on that about when you asked that, so I'll have the code up once I get past this undefined vtable bug – pmelanson Jun 11 '12 at 04:20
  • whatever, I came up with a simpler way of splitting files that doesn't use extern, even though it doesn't cut as many lines. Thanks for the help anyways. – pmelanson Jun 11 '12 at 05:03

1 Answers1

0

Are including the other source files into the main source? You should not do that, especially if you include the same header file in several source files.

You should compile each source file by itself, and the use the linker to link those files together.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621