Thread: linking error fun

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743

    linking error fun

    So I have an include guard on this header file, but it doesn't seem to be working....

    Code:
    #ifndef __HEAP_H_
    #define __HEAP_H_
    
    ........some structs.......
    
    .....some functions.......
    
    #endif /* __HEAP_H_ */
    For some reason it's not working. I include heap.h in file1.c, and then again in file2.c, but when I compile it all, it's giving me linking errors saying that all the functions were already defined in file1.obj

    To be exact:
    1>Linking...
    1>os345p2.obj : error LNK2005: _heap_init already defined in os345.obj
    1>os345p2.obj : error LNK2005: _heap_isEmpty already defined in os345.obj
    1>os345p2.obj : error LNK2005: _heap_isFull already defined in os345.obj
    1>os345p2.obj : error LNK2005: _heap_heapify already defined in os345.obj
    1>os345p2.obj : error LNK2005: _heap_addItem already defined in os345.obj
    1>os345p2.obj : error LNK2005: _heap_extractMax already defined in os345.obj
    1>os345p2.obj : error LNK2005: _heap_extractNode already defined in os345.obj
    Any thoughts?
    My Website

    "Circular logic is good because it is."

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    So heap_init & co are functions defined within the header?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you do not put function bodies in the header, only prototypes

    fucntions could be declared several times, but defined only once
    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
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    ah yes.....that's right stupid me
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems linking with g++
    By Just in forum Linux Programming
    Replies: 11
    Last Post: 07-24-2006, 01:35 AM
  2. strange linking error -- can not find shared library
    By George2 in forum C Programming
    Replies: 2
    Last Post: 07-10-2006, 10:51 PM
  3. Replies: 8
    Last Post: 04-27-2006, 10:39 AM
  4. Grrr.... SDL Linking Problem
    By 7EVEN in forum Game Programming
    Replies: 5
    Last Post: 08-12-2005, 08:44 PM
  5. Linking error with DirectDrawCreateEx
    By jjj93421 in forum Game Programming
    Replies: 6
    Last Post: 04-06-2004, 03:57 PM