compilation problem

This is a discussion on compilation problem within the C Programming forums, part of the General Programming Boards category; hi everyone, I was trying to run a program with three files( file1.c, file2.c and file3.h). I have my main ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    28

    compilation problem

    hi everyone,

    I was trying to run a program with three files( file1.c, file2.c and file3.h). I have my main in the file2.c and I put some prototype call from file1.c by using the keyword extern and at the top of file1.c I also have the same protoypes declerations as the ones called in file2.c or see below what I have:


    file2.c /* calls some funtions infile1.c */
    extern int foo()
    extern byte foo2()
    main () .....



    file1.c
    int foo() /* protoype */
    int foo()...




    it is giving me this type error when run:

    ! ./feal8.o(.text+0x0):feal8.c: multiple definition of `Decrypt'
    ! ./feal8.o(.text+0x0):feal8.c: first defined here
    ! ./feal8.o(.text+0xc4):feal8.c: multiple definition of `DissQ1'


    can anyone tell me why it gives me this error ?

  2. #2
    *
    Guest
    You need to tell the compiler to include a header file only once.


    In every header file, put tags like this (one at the top and bottom):



    headerfile.h -----------------------------------------

    Code:
    #ifndef __headerfile__
    #define __headerfile__
    
    ... typedefs ...
    ... extern declarations ...
    
    #endif __headerfile__

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    #ifndef __headerfile__
    #define __headerfile__
    
    ... typedefs ...
    ... extern declarations ...
    
    #endif __headerfile__
    Why does everyone do this? Leading underscores are reserved for the implementation, so unless you are writing a compiler this is incorrect. Otherwise the solution is good.

    -Prelude
    My best code is written with the delete key.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    I rather suspect that you have actual code (and not just prototypes) in the .h file.

    So whilst the include guards are a good idea, and should be used, I don't think they will solve your problem.

    The solution (if this is the problem) is to make sure your .h contains prototypes only, and all the actual code is in the two .c files.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  2. Compilation problem
    By OSDever in forum C++ Programming
    Replies: 10
    Last Post: 09-08-2005, 06:42 AM
  3. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  4. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM

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