Thread: header file error

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    58

    header file error

    Hi everyone,

    if I include the header,

    - #include "Test_Case.h"

    and also define it,

    #ifndef _TEST_CASE_H
    #define _TEST_CASE_H
    code ~~
    #endif

    anyone know why do i still get this :

    one or more multiply defined symbols found
    Error executing link.exe.

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    We'd have to see more code. Be warned that variables and macros starting with an underscore '_' are reserved to whoever implemented the libraries that come with your compiler. Basically, that means that if you create a variable that starts with an underscore, it might already be used and it will cause an error. This is probably not the case here so we need to see more code. Give us only the pre-compiler code (i.e. lines that start with #) since this is the linking part and as you can tell by the error, the linking has failed (which comes before compiling).

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    the linking has failed (which comes before compiling).
    Always thought that linkage is done after compilation...

    one or more multiply defined symbols found
    Check that you don't define global variables in your header.
    And you should not put any function bodies there also.
    The whole header file text will be usefull
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    If it's a linker error, check that you haven't linked any object file multiple times. If you follow the standard convention of declaration in header files and implementation in source files, the code should compile without problems, as far as I see.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > anyone know why do i still get this :
    Because include guards only work just the once for each source file you include it in.

    Including the same file in several source files will create several definitions, if your header file contains definitions.

    The real answer is to make sure your header only contains declarations.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Be warned that variables and macros starting with an underscore '_' are reserved to whoever implemented the libraries that come with your compiler. Basically, that means that if you create a variable that starts with an underscore, it might already be used and it will cause an error.
    Actually, identifiers starting with an underscore followed by another underscore or an uppercase letter are reserved. That is, these are reserved:
    Code:
    _INCLUSION_GUARD
    __reserved
    ___something
    But these aren't:
    Code:
    _variable
    _256
    [edit] Sort of like this, if you like REs:
    Code:
    if(name =~ /_[A-Z_]/) { reserved(); }
    [/edit]

    One example of what Salem said is declaring a non-static global variable in a header file. Including this header file multiple times would cause an error much like you posted.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    58
    Thanks everyone.
    I manage to solve it.

  8. #8
    Registered User
    Join Date
    Dec 2005
    Posts
    136
    Could u please tell us, how did u manage to solve it??
    S_ccess is waiting for u. Go Ahead, put u there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  2. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM