Thread: I get the same build errors multiple times while using include guards

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    4

    I get the same build errors multiple times while using include guards

    The header file:
    Code:
    #ifndef HEADERS_H
    #define HEADERS_H
    
    //Class declarations
    
    #endif
    I include this file in multiple others, but I thought this should take care of it...These are the errors I get:

    Code:
    1>------ Build started: Project: ppppConsole, Configuration: Debug Win32 ------
    1>Compiling...
    1>Setup.cpp
    1>c:\users\nancy\documents\visual studio 2008\projects\ppppconsole - copy - debug mode\ppppconsole\headers.h(281) : error C2146: syntax error : missing ';' before identifier 'BMP'
    1>Generating Code...
    1>Compiling...
    1>Prey.cpp
    1>c:\users\nancy\documents\visual studio 2008\projects\ppppconsole - copy - debug mode\ppppconsole\headers.h(281) : error C2146: syntax error : missing ';' before identifier 'BMP'
    1>Generating Code...
    1>Compiling...
    1>Predator.cpp
    1>c:\users\nancy\documents\visual studio 2008\projects\ppppconsole - copy - debug mode\ppppconsole\headers.h(281) : error C2146: syntax error : missing ';' before identifier 'BMP'
    1>Generating Code...
    1>Compiling...
    1>Map.cpp
    1>c:\users\nancy\documents\visual studio 2008\projects\ppppconsole - copy - debug mode\ppppconsole\headers.h(281) : error C2146: syntax error : missing ';' before identifier 'BMP'
    1>Generating Code...
    1>Compiling...
    1>main.cpp
    1>c:\users\nancy\documents\visual studio 2008\projects\ppppconsole - copy - debug mode\ppppconsole\headers.h(281) : error C2146: syntax error : missing ';' before identifier 'BMP'
    1>c:\users\nancy\documents\visual studio 2008\projects\ppppconsole - copy - debug mode\ppppconsole\main.cpp(83) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
    1>Generating Code...
    1>Compiling...
    1>GameSetup.cpp
    1>c:\users\nancy\documents\visual studio 2008\projects\ppppconsole - copy - debug mode\ppppconsole\headers.h(281) : error C2146: syntax error : missing ';' before identifier 'BMP'
    1>Generating Code...
    1>Compiling...
    1>GameEngine.cpp
    1>c:\users\nancy\documents\visual studio 2008\projects\ppppconsole - copy - debug mode\ppppconsole\headers.h(281) : error C2146: syntax error : missing ';' before identifier 'BMP'
    1>Generating Code...
    1>Compiling...
    1>Creature.cpp
    1>c:\users\nancy\documents\visual studio 2008\projects\ppppconsole - copy - debug mode\ppppconsole\headers.h(281) : error C2146: syntax error : missing ';' before identifier 'BMP'
    1>Generating Code...
    1>Compiling...
    1>BMP.cpp
    1>c:\users\nancy\documents\visual studio 2008\projects\ppppconsole - copy - debug mode\ppppconsole\headers.h(281) : error C2146: syntax error : missing ';' before identifier 'BMP'
    Also, I'm a bit confused about all the includes, why do I have to include (for example) iostream in all the cpp files that use stuff defined therein when I've already included it in main.cpp (where int main() is)?!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You have to include in every file that uses it because .cpp files aren't compiled together; they are compiled separately.

    Also, include guards can't save you from missing semicolons -- adding semicolons where they belong will save you from missing semicolons.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4
    :/ No I removed the semicolon deliberately to show you that I get the same error more than once!!!

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by en_em_i View Post
    :/ No I removed the semicolon deliberately to show you that I get the same error more than once!!!
    You want -- nay, need -- to have the same error more than once. If you don't you are so screwed. Every cpp file is compiled separately. Not related to each other in any way at all -- the linker merges the object files after everything is compiled.

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    4
    Uhuh, nothing's wrong then =D Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. in a constant loop with threads using socket
    By kiros88 in forum C Programming
    Replies: 1
    Last Post: 08-21-2009, 06:34 PM
  2. Buidl Library with ./configure script
    By Jardon in forum C Programming
    Replies: 6
    Last Post: 07-24-2009, 09:36 AM
  3. Something about probablility
    By mike_g in forum A Brief History of Cprogramming.com
    Replies: 116
    Last Post: 03-13-2008, 05:33 PM
  4. Header file include order
    By cunnus88 in forum C++ Programming
    Replies: 6
    Last Post: 05-17-2006, 03:22 PM
  5. Header file include guards
    By foniks munkee in forum C Programming
    Replies: 4
    Last Post: 03-22-2002, 12:33 AM