Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Extern vars unresolved at link

Extern vars unresolved at link

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jimNLX
    wrote on last edited by
    #1

    I have a program with the following defined in a header file that is included in many files. I need the var to be global so I have this in the header file: Global.h typedef struct _D2N_GLBL_STRUCT { long runways_line_pos; ... }D2N_GLBL_STRUCT; extern D2N_GLBL_STRUCT *D2N_GLBL; .cpp D2N_GLBL->runway... = -1; I get linker errors saying it is undefined or already defined in files that I've include the global.h file. What am I doing wrong? Thanks for any help

    N P 2 Replies Last reply
    0
    • J jimNLX

      I have a program with the following defined in a header file that is included in many files. I need the var to be global so I have this in the header file: Global.h typedef struct _D2N_GLBL_STRUCT { long runways_line_pos; ... }D2N_GLBL_STRUCT; extern D2N_GLBL_STRUCT *D2N_GLBL; .cpp D2N_GLBL->runway... = -1; I get linker errors saying it is undefined or already defined in files that I've include the global.h file. What am I doing wrong? Thanks for any help

      N Offline
      N Offline
      Neville Franks
      wrote on last edited by
      #2

      You need to include global variables in one source file without the "extern" keyword. One way to do this is: #ifndef INIT_MY_GLOBAL extern #endif D2N_GLBL_STRUCT *D2N_GLBL; then in your main .cpp file use: #define INIT_MY_GLOBAL #include <global.h> Having said all that globals are a realy bad idea.:( Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com

      1 Reply Last reply
      0
      • J jimNLX

        I have a program with the following defined in a header file that is included in many files. I need the var to be global so I have this in the header file: Global.h typedef struct _D2N_GLBL_STRUCT { long runways_line_pos; ... }D2N_GLBL_STRUCT; extern D2N_GLBL_STRUCT *D2N_GLBL; .cpp D2N_GLBL->runway... = -1; I get linker errors saying it is undefined or already defined in files that I've include the global.h file. What am I doing wrong? Thanks for any help

        P Offline
        P Offline
        Prakash Nadar
        wrote on last edited by
        #3

        In the global.h you have extern D2N_GLBL_STRUCT *D2N_GLBL; Did you put D2N_GLBL_STRUCT *D2N_GLBL; in one of the .cpp file?? if you dont do it, it will give you linker error.


        P.R.A.K.A.S.H

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups