Linker errors - Multiple Source files

This is a discussion on Linker errors - Multiple Source files within the C Programming forums, part of the General Programming Boards category; Hi, I am trying to compile a program having multiple files. I have a common header file which i am ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    134

    Linker errors - Multiple Source files

    Hi,

    I am trying to compile a program having multiple files. I have a common header file which i am including in 3 source files. Multiple inclusion is protected by wrapping the contents of .h file using "#ifndef"

    For e.g. I have following in my header file

    Code:
    #ifndef PPTPCLIENT_H
    #define PPTPCLIENT_H
    
    const char control_reply_result_codes[6][100] = {	
    	" ",
    	"Successful channel establishment",
    	"General error -- Error Codeindicates the problem",
    	"Command channel already exists",
    	"Requester is not authorized to establish a command channel",
    	"The protocol version of the requester is not supported"
    };
    
    const char general_error_codes[6][100] = { 
    	"No General Error",
    	"No Control Connection exits yet for this PAC-PNS pair",
    	"Length is wrong or Magic Cookie value is incorrect",
    	"One of the field values was out of range or reserved field was non-zero",
    	"The Call ID is invalid in this context",
    	"A generic vendor-specific error occured in the PAC"
    };
    
    const char stop_reason_codes[4][100] = { 
    	" ",
    	"General request to clear control connection",
    	"Can't support peer's version of the protocol",
    	"Requester is being shutdown"
    };
    
    const char og_result_code [8][150] = {	
    	" ",
    	"Call established with no errors",
    	"Outgoing call not established for the reason indicated in error code",
    	"Outgoing call failed due to no carrier detected",
    	"Outgoing call failed due to detection of busy signal",
    	"Outgoing Call failed due to lack of a dial tone",
    	"Outgoing Call was not established within time allotted by PAC",
    	"Outgoing Call administratively prohibited"
    };
    ....../*Some other similar declarations */
    #endif
    How ever I am getting linker errors for multiple inclusion of above array and similar other arrays.

    gcc -g -o pptpclient pclientmain.c pclientfunction.c pptputils.c
    /tmp/ccMMMtIa.o(.rodata+0x0): In function `printHelp':
    /home/snoopy/pptp/pclientfunction.c:4: multiple definition of `control_reply_result_codes'
    /tmp/cccyJsV6.o(.rodata+0x0):/home/snoopy/pptp/pclientmain.c:4: first defined here
    /tmp/ccMMMtIa.o(.rodata+0x260): multiple definition of `general_error_codes'
    /tmp/cccyJsV6.o(.rodata+0x260): first defined here
    /tmp/ccMMMtIa.o(.rodata+0x4c0): multiple definition of `stop_reason_codes'
    /tmp/cccyJsV6.o(.rodata+0x4c0): first defined here
    /tmp/ccMMMtIa.o(.rodata+0x660): multiple definition of `og_result_code'
    /tmp/cccyJsV6.o(.rodata+0x660): first defined here
    Can some one help me to figure out where the problem is?

    Thanks,

  2. #2
    Widdle Coding Peon Aerie's Avatar
    Join Date
    Dec 2004
    Posts
    115
    I dunno much about linking and multiple files, but why aren't these arrays of pointers to string constants? Seems you're wasting a lot of array space here, when you could just have
    Code:
    const char *someptr[] = { 
        "String", 
        "String2",
         ...
         };
    I live in a giant bucket.

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Try this:
    Put all the variables in a .c file, in the .h file put in:
    extern <type> <name>;

  4. #4
    Registered User
    Join Date
    Apr 2005
    Posts
    134
    Thanks guys..problem solved.

    Aerie/Thantos: thanks for that suggestions, Changed it back as per your suggestions.

    Thanks,

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mutex across multiple source files
    By Quasar in forum Linux Programming
    Replies: 7
    Last Post: 12-04-2007, 08:25 AM
  2. pseudocode for multiple source files
    By Calef13 in forum C++ Programming
    Replies: 4
    Last Post: 11-13-2007, 09:07 AM
  3. Sneaky little linker errors...
    By Tozar in forum C++ Programming
    Replies: 8
    Last Post: 10-25-2006, 06:40 AM
  4. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  5. Multiple source files for one program
    By gflores in forum C++ Programming
    Replies: 3
    Last Post: 08-15-2004, 03:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21