Nasty linker problem; multiply defined

This is a discussion on Nasty linker problem; multiply defined within the C++ Programming forums, part of the General Programming Boards category; This is a really frustrating error. I've tried everything I can think of and it still doesn't link properly. Now, ...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Nasty linker problem; multiply defined

    This is a really frustrating error. I've tried everything I can think of and it still doesn't link properly.

    Now, I have three headers: aux.h, start.h and dataf.h, and each one is wrapped in inclusion guards. I have two source files: aotrn.cpp and dataf.cpp. Now, dataf.cpp needs to include aux.h and dataf.h, and aotrn.cpp (at the moment) only needs start.h.

    I get the following error:

    /tmp/ccYdCaoB.o(.text+0x0): In function `KillGame(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
    : multiple definition of `KillGame(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
    /tmp/ccZuFcvP.o(.text+0x0): first defined here
    /tmp/ccYdCaoB.o(.text+0x50): In function `wait_ms(long)':
    : multiple definition of `wait_ms(long)'
    /tmp/ccZuFcvP.o(.text+0x50): first defined here
    /tmp/ccYdCaoB.o(.text+0x80): In function `fcout(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
    : multiple definition of `fcout(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
    /tmp/ccZuFcvP.o(.text+0x80): first defined here
    /tmp/ccYdCaoB.o(.text+0x100): In function `File_Encrypt(char*, char*)':
    : multiple definition of `File_Encrypt(char*, char*)'
    /tmp/ccZuFcvP.o(.text+0x100): first defined here
    /tmp/ccYdCaoB.o(.text+0x210): In function `ForkExecute(char*)':
    : multiple definition of `ForkExecute(char*)'
    /tmp/ccZuFcvP.o(.text+0x210): first defined here
    collect2: ld returned 1 exit status
    make: *** [AoTRN] Error 1
    I don't want to post the source up as that would mean posting 5 files each more than about 30 lines.

    *edit*

    Oh yeah, I'm using G++ 3.3.5
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    You don't have function definitions in header files do you - because that's bad news unless
    a) the functions are static
    b) the functions are inline
    c) the functions are templates
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    If you mean like this:

    Code:
    // aux.h
    
    void foo()
    {
    	// nooooo
    }
    Then yeah, I have. So I need to declare the functions in the .h files and define them in .cpp files?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    > Then yeah, I have. So I need to declare the functions in the .h files and define them in .cpp files?
    Yes.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    respect_for_Salem += 1;
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Variables already defined while linking.
    By xconspirisist in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2005, 05:20 AM
  2. Linker problem in MicroSoft Visual C++
    By Christer in forum C++ Programming
    Replies: 3
    Last Post: 12-10-2002, 12:08 PM
  3. Linker problem in Visual C++ 6.0
    By Christer in forum Windows Programming
    Replies: 1
    Last Post: 12-10-2002, 10:57 AM
  4. problem with output
    By Garfield in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 07:34 PM
  5. Error: *&*$%$.o Multiply Defined
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-01-2001, 12:02 PM

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