CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2003
    Posts
    99

    multiple declaration error

    I have three files say

    common_defs.h

    main.c
    #includes common_defs.h as well as common_defs.h
    contains the main function

    abc.c
    #includes common_defs.h


    i compile main.c and abs.c separately to creeate
    the respective .o files
    Now for the final compilation, my compiler (icc) gives multiple declaration error for all the constants defined in common_defs.h

    Any solution,

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Did you add inclusion guards to your header files...
    Code:
    #ifndef __CLASS_A_HPP
    #define __CLASS_A_HPP
    
    // Your class declaration
    
    #endif

  3. #3
    Join Date
    Dec 2003
    Posts
    99
    Yes I did

    One more finding
    I am using C. Also using constants are allowed as per the new C standard

    The other thing i just found
    is that if i use #defines instead of const int things work just fine

    Is there any diff between the C and C++ constants that is causing problems.
    I have also used extern "c"


    Thanks

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Well...you might want to take a look at the following FAQ...

  5. #5
    Join Date
    Dec 2003
    Posts
    99
    Are you suggesting to use something like
    extern const int x ?


    To be very precise my problem is because I compile in stages
    first main.o is created
    then abc.o is created
    both have space allocated for the common_defs

    Now when i compile the object files together there is a multiple declaration error ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured