Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Jan 2009

    error:undefined reference

    I have included a header file named Flag.h
    the file has only this line of code
    extern TBool iEnableLogging;

    I have included the above header file in some other file.
    and have used the iEnableLogging in this file.

    But when I build the code it gives me an error :
    "undefined reference to iEnableLogging "
    Please help me why am I getting this error?
    Gaurav Gupta

  2. #2
    Nokia Developer Expert
    Join Date
    Jun 2008

    Re: error:undefined reference

    explanation of extern.

    The extern keyword declares a variable or function and specifies that it has external linkage (its name is visible from files other than the one in which it's defined). When modifying a variable, extern specifies that the variable has static duration (it is allocated when the program begins and deallocated when the program ends). The variable or function may be defined in another source file, or later in the same file. Declarations of variables and functions at file scope are external by default.

    you need to check whether the corresponding library files is included.

  3. #3
    Super Contributor
    Join Date
    Oct 2007
    જુનાગઢ - India

    Re: error:undefined reference

    extern is some what similar to forward declaration. If variable declared with extern keyword means that it is defined in some other files. Anyway external variable are global variables, and in symbian use of global variable is not recommanded. Alternatively you can declare this variable at class level (in base class, appview/appui).

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Oslo, Norway

    Re: error:undefined reference

    The immediate soultion would be writing "TBool iEnableLogging;" into any .cpp file of yours (without the "extern", and outside of any method-scope). Then you will be able to access that single variable from whereever you have #include-d "Flag.h".
    Anyway, use of global variables is discouraged, and the name "iEnableLogging" is mis-leading (it suggests a member variable, "EnableLogging" would be better for a global variable).

Similar Threads

  1. Replies: 16
    Last Post: 2008-08-20, 21:03
  2. [moved] HELP! Phone Debug (GCCE)
    By joseph.m in forum Symbian
    Replies: 18
    Last Post: 2008-07-14, 10:42
  3. carbide c++ can't find headers.!!
    By nokia_maniac in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 29
    Last Post: 2007-12-19, 12:54
  4. CameraApp Example 3rd Edition
    By bigbadwolf in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2007-05-28, 19:13
  5. file not found
    By praktikant in forum Symbian
    Replies: 16
    Last Post: 2007-05-09, 15:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts