Thread: weird problem with .h files

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    weird problem with .h files

    I just noticed that when you have a header file that declares variables, if you include it in another header file, it tries to declare the variables twice which gives redefinition errors. I discovered this trying to get my project to work. It compiles, but here are the errors:

    Code:
    Compiling...
    main.cpp
    Ship.cpp
    Linking...
    Ship.obj : error LNK2005: "struct HBITMAP__ * shipmask" (?shipmask@@3PAUHBITMAP__@@A) already defined in main.obj
    Ship.obj : error LNK2005: "struct HBITMAP__ * shipvar" (?shipvar@@3PAUHBITMAP__@@A) already defined in main.obj
    Ship.obj : error LNK2005: "struct SHIP player" (?player@@3USHIP@@A) already defined in main.obj
    Debug/Windows Tutorial.exe : fatal error LNK1169: one or more multiply defined symbols found
    Error executing link.exe.
    
    Windows Tutorial.exe - 4 error(s), 0 warning(s)

  2. #2
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    its not like this has been posted ONE FRICKING MILLION TIMES BEFORE, but do this with each of your header files:

    Code:
    ==========foobar.h=============
    #ifndef FOOBAR_HEADER_FILE
    #define FOOBAR_HEADER_FILE
    
    // put everything else here
    
    #endif
    next time try a search, eh?
    hello, internet!

  3. #3
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    Thank you vVv. I got it to work, however still don't understand why I need to do this. Would you be able to explain this or redirect me to somewhere else that can?
    Last edited by Leeman_s; 12-22-2002 at 05:14 PM.

  4. #4
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    Wow, very nice! This has just opened up a whole new level of program organization! Now I don't need any functions declared in main.cpp except the windows ones. Thanks again vVv.

  5. #5
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Hehe, wouldn't it be convenient to learn basic C++ programming before learning game development?
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  6. #6
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    Well, it's sorta hard to learn the regular way when you don't take any c++ classes and just learn on your own.

    lol, this is how it went for me. I bought MSVC++, only knew how to program in BASIC. Talk about a huge change in compiler level of difficulty, if you will. All I had to learn was the compiler, my book, and the internet.

  7. #7
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by Leeman_s
    Well, it's sorta hard to learn the regular way when you don't take any c++ classes and just learn on your own.
    I have acquired like 1% of my skill in C++ though classes, the rest I've studied on my own.
    I borrow books and read them - IMO a very good way to learn programming.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  8. #8
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    sang is that website yours? in your sig.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird problem with sscanf
    By g4j31a5 in forum C++ Programming
    Replies: 17
    Last Post: 10-04-2006, 09:16 PM
  2. weird problem!
    By spank in forum C Programming
    Replies: 2
    Last Post: 04-08-2006, 03:26 AM
  3. Making .h files
    By Diamonds in forum C++ Programming
    Replies: 3
    Last Post: 11-14-2002, 02:05 PM
  4. Problem with cgi script - can't rename files
    By bjdea1 in forum C Programming
    Replies: 2
    Last Post: 12-12-2001, 04:09 PM
  5. opengl .h files
    By Unregistered in forum Game Programming
    Replies: 3
    Last Post: 10-18-2001, 08:32 PM