Results 1 to 17 of 17

Thread: Link error !?!?!?!?!

  1. #1

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228

    Arrow Link error !?!?!?!?!

    Ok, another stupid problem! I compile my program... so far so good. Then it gets to the linking part and it gives me a mother-load of errors, pretty much an error for every function i have defined in my header file:

    error: 'int Render() [some other stuff]' already defined in MyHeader.obj

    What does this mean and how do i fix it?????
    To protect time is to protect everything...

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You don't put the actual code into the header, just the prototype. The code needs to go into a separate .cpp file, otherwise you will, obviously, get these linker errors because as far as the linker is concerned, the same function code exists in every .cpp file that includes your header.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    I know.... I have only proto types in my .h file and the actual code is in a .cpp file. I have multiple .cpp files using the same .h file. Might that cause this problem?
    To protect time is to protect everything...

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    No, it shouldn't make any difference.

    Do you have the same function defined in the .cpp files then? The linker's basically telling you it's collected all the object files together, and it's found more than one function (code) with the same prototype.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    There's a way to include any declarations, prototypes, constants, etc only once. Only the first time the header is included, its contents are expanded in the compiler.
    Code:
    #ifndef MYFILE_H
    #define MYFILE_H
    
    (put all stuff from your header file here)
    
    #endif
    In some cases (I think it's with DLL's) it is absolutely necessary to include your header file only once.

  6. #6

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    Well I just dont know whats wrong then...

    I have:

    #ifndef MY_HEADER
    #define MY_HEADER

    ..... header code

    #endif

    The compiler (which is VC++ 6.0 by the way) is telling me that I have many many different functions and variables "already defined in MyHeader.obj". I know i don't have all of them defined in more than one .cpp file. In fact I'm almost positive that I don't have any. ??????????????
    To protect time is to protect everything...

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Try a "Rebuild All".
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    Same result.....

    I Have 1 .h file and 3 .cpp files. All of the .cpp files include the .h file.

    one_cpp.obj error: LNK2005 "bool SomeBool" (C++ Mangled name) already defined in first_cpp.obj

    one_cpp.obj error: LNK2005 "int SomeFunc" (C++ mangled...) already defined in first_cpp.obj

    .............???? there are 10 errors all like this.... i've never had this problem b4.... I don't get it ?????
    To protect time is to protect everything...

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Can you post the contents of your .h file?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  10. #10

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    Ok, here goes.........

    Code:
    #ifndef MY_HEADER
    #define MY_HEADER
    #pragma once
    // Includes...
    #include <windows.h>
    #include <d3dx8.h>
    
    // Macros...
    #define R_OK = 100
    #define R_ERROR = 101
    #define R_STOP_RENDER = 102
    #define DLL_OK = 800
    #define DLL_ERROR = 801
    
    // Globals...
    typedef INT (*DLLFUNC_VOID)(void);
    typedef INT (*DLLFUNC_RETVAL)(DXAPP_SYSTEM *dll_dx);
    typedef INT (*DLLFUNC_STRRET)(const char *str, long sTyp);
    HINSTANCE hDLL;
    DLLFUNC_STRRET DLL_SRETURN;
    DLLFUNC_RETVAL DLL_CREATE;
    DLLFUNC_RETVAL DLL_SET_DXAPPSYS;
    DLLFUNC_VOID DLL_UPDATE;
    DLLFUNC_VOID DLL_RELEASE;
    HWND APPhWnd;
    bool HALRender = false;
    bool SceneInit = false;
    
    // Prototypes...
    LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
    HRESULT InitD3D( HWND hWnd );
    INT InitScene( const char *dll );
    INT UpdateScene( const char * dll );
    INT EndScene( const char *dll );
    INT Render();
    void CleanUp();
    void ErrorMsg( const char *msg, const char *caption, bool fatal );
    void Quit();
    
    void OneTimeRender();
    
    // End MY_HEADER
    #endif
    I've tired taking the #pragma once in and out and it results in no change.......
    To protect time is to protect everything...

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Do all three .cpp files provide code for those functions, or is there only ever one set of source, in one file?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    Each .cpp file provides code for their share of functions. I have one .cpp file handling all the windows stuff, and another handling the direct 3d stuff. The third has all been commented out right now b/c it has bugs.
    To protect time is to protect everything...

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    In that case, I have absolutely no idea.

    The only reason the linker should complain is if more than one .cpp file contains code for the same function, which you've said isn't the case.

    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  14. #14

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    Well i can like quadruple check but im pretty sure...... thanx anyway tho...
    To protect time is to protect everything...

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I'd understand if the linker complained about the variables...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  16. #16
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    this is going to sound stupid, but i think it worked for me once.
    erase the debug folder, and copy the whole project somewhere else on your hd, then recompile..i dont know why this would work, but it did once for me
    Amon Ra
    The Power of Learning.

  17. #17

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    Well if i put the option FORCE:MULTIPLE in the linker options it sets all those errors as warnings.... so yeah i guess that works... the program seems to run fine... but i dont know if i'll run into something along the way.
    To protect time is to protect everything...

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