Results 1 to 6 of 6

Thread: Linker Error

  1. #1
    Guest

    Linker Error

    This isn't a direct OpenGL question but if anyone can give me some assistance that would be great. I am having "Unresolved externel....." errors when attempting to program an OpenGL program. I am using different header files for each module of the program. There is a particular module that contains all my global variables and functions. When I declare the variable straight out, my compiler BCB5, says that there are multiple definitions of the variable. When I declare the variable with extern, I get the unresolved error.
    Is there any hints anyone can give me?

  2. #2
    Guest

    Re: Linker Error

    So what is the error?

    We can't read your mind.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Location
    Kingston, Jamaica, W.I.
    Posts
    282

    Re: Linker Error

    Have you entered code to ensure a file gets included only once. This way you won't get it redefined because of multiple inclusions.

    eg.
    #ifndef MYFILEINCLUDED
    #define MYFILEINCLUDED

    Code...

    #endif

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2002
    Location
    San Antonio,TX, U.S.A
    Posts
    1

    Re: Linker Error

    Yep, you do need to make certain that your header files are "wrapped" to guard against multiple inclusion by the preprocessor:

    Code :
    #ifndef MYFILEINCLUDED
    #define MYFILEINCLUDED
    .
    .
    .
    #endif
    But, if you wrap the header, you can still have trouble if your header file contains definitions. It is good practice for your header files to contain only declarations.
    Example:
    Code :
    #ifndef _MYHEADER_H
    #define _MYHEADER_H
     
    extern int myinteger; // Ok, declaration of
                          // myinteger, it must
                          // be defined elsewhere
     
    float myfloat;        // risky, during 
                          // compilation, if more
                          // than one .c/.cpp
                          // includes this header
                          // the symbol myfloat
                          // will be duplicated
                          // and many linkers 
                          // will complain
     
    #endif//_MYHEADER_H
    I'm a little rusty on my C/C++, but I believe these facts to be correct.


    [This message has been edited by ComoNo (edited 02-04-2002).]

  5. #5
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Posts
    292

    Re: Linker Error

    Why dont you try including #pragma once in the beginning of your code....
    e.g.

    #pragma once

    ...... your code .........

  6. #6
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Location
    Kingston, Jamaica, W.I.
    Posts
    282

    Re: Linker Error

    Sorry, I've never used pragma so I don't know how it works. ComoNo is right though. If you place only declarations in your header files it can save you a lot of headaches.

    PS: Does anyone know where I can find a good MS VC++6.0 discussion forum? There's still a lot I need to learn about the program.

Similar Threads

  1. Linker error
    By Zhugie in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-18-2007, 12:29 PM
  2. Linker error
    By Loffen in forum OpenGL: Windows
    Replies: 1
    Last Post: 08-19-2005, 04:53 AM
  3. Linker Error
    By Suf in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-16-2002, 08:43 AM
  4. linker error need help!!!!!!!!!!!!!!!!!!!!!!!
    By incus in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 05-17-2002, 10:31 PM
  5. Linker error
    By JodoKaast in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-25-2002, 01:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean