C语言程序设计 1.10 Undefined symbols for architecture x86_64: "_line", referenced from:

#include 

#define MAXLINE 1000

int getLine(void);
void copy(void);

int main(int argc, const char * argv[]) {
    int len;
    extern int max;
    extern char longest[];

    max = 0;
    while ((len = getLine())>0) {
        if (len>max) {
            max = len;
            copy();
        }
    }
    if (max>0) {
        printf("%s",longest);
    }
    return 0;

    
}

int getLine(void){
    int c = 0,i;
    extern char line[];
    for ( i = 0; i < MAXLINE - 1 && (c=getchar())!=EOF && c != '\n'; ) {
        line[i] = c;
    }
    if (c == '\n') {
        line[i] = c;
        ++i;
    }
    line[i] = '\0';
    return i;
}
void copy(void){
    int i;
    extern char line[], longest[];
    i = 0;
    while ((longest[i] = line[i]) != '\0') {
        i++;
    }
}

报错如下:

Undefined symbols for architecture x86_64:

  "_line", referenced from:

      _getLine in main.o

      _copy in main.o

  "_longest", referenced from:

      _main in main.o

      _copy in main.o

  "_max", referenced from:

      _main in main.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

你可能感兴趣的:(C)