Thread: Header file problem

  1. #1
    Unregistered
    Guest

    Header file problem

    Hi, I have 2 cpp files, each one including the test.h header file.

    my header file seems like this:

    #ifndef TESTFILE
    #define TESTFILE

    int test;
    char *hello;

    #endif

    The problem is that the linker says
    'int test (?test@@3HA) already defined in test.obj'
    'char *hello (?hello@@3HA) already defined in test.obj'

    Ive tried pragma once, but the above, shouldnt fix the problem??
    It doesnt..
    Please help, thanks!

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    139
    try manually deleting the obj file
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

  3. #3
    Unregistered
    Guest
    without seeing more of your code I would be suspicious of a name clash.

  4. #4
    Unregistered
    Guest
    Name clash? Meaning?
    The rest of my code are 2 cpp files including the same header.

  5. #5
    Unregistered
    Guest
    Oh, if I delete the obj file, it works! but isnt there an automated way??

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    139
    force the compiler to recompile all. don't remember how right now to tired. Lazy compilers *sigh*
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

  7. #7
    Unregistered
    Guest
    Ohh yes!! works! Thank you man, you saved my life )

  8. #8
    Unregistered
    Guest
    Oups, no, it didnt work.. Sorry, my mistake, i forgot to include the header file 2nd time.. still the same error..

  9. #9
    Registered User
    Join Date
    Apr 2002
    Posts
    139
    post the files so I can see what they look like to determine what the problem is...
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

  10. #10
    Registered User
    Join Date
    May 2002
    Posts
    49
    The mistake is: u DEFINE a variable in a header. Remember: always DECLARE but not DEFINE variables in header file.
    Move the
    Code:
    int test;
    char *hello;
    to a cpp file; And write in header file like this:
    Code:
    extern int test;
    extern char*hello;
    Hello, everyone.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding Header Files
    By Kaidao in forum C++ Programming
    Replies: 11
    Last Post: 03-25-2008, 10:02 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM