Thread: extern char* problem

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    1

    extern char* problem

    Hi, I'm quite new to C. I have 4 .h files and one header file.

    header.h
    Code:
    //variables
    extern char CWD[PATH_MAX];
    fileio.c
    Code:
    char CWD[PATH_MAX];
    strcpy(CWD,temp);

    haar.c
    Code:
    strcpy(imagePath, CWD);
    I'm getting the error:
    haar.c:62: undefined reference to `CWD'
    I've looked around the net quite a bit about extern variables and this seems to be the right thing to do - declare extern in header (which is included in every .c file) and then initialise it once (in fileio.c) and use it anywhere (in haar.c).

    Why am i still getting this error?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You have to declare it in file scope in fileio.c. Given that immediately underneath it is "strcpy(CWD,temp)", that indicates to me that your CWD lives inside a function, and extern can't help you there.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    You need an extern declaration for CWD in haar.c, outside of any function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. problem with extern variables
    By crash88 in forum C Programming
    Replies: 11
    Last Post: 05-05-2006, 01:44 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM