2016-11-06 70 views
0

我遇到了一個錯誤,當我做文件 什麼是「架構x86_64的未定義符號:」是什麼意思?

Undefined symbols for architecture x86_64: 
    "_extendArray", referenced from: 
     _main in lineSort-b1083a.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
make: *** [lineSort] Error 1 

我環顧四周,幾個答案,但沒有真正意義的我。我不知道我的代碼有什麼問題。我的代碼如下所示:

#include <stdio.h> 
#include <stdlib.h> 
#include "utilityFunction.h" 

int main(int argc, char**argv){ 
    FILE *filename; 
    size_t len = 0; 
    char *line = NULL; 
    int index; 
    int countLine = 0, i = 0; 
    char** new_array = malloc(16 * sizeof(char*)); 

    for(index = 1; index < argc; index++){ //loop for all files name you input in the command line 
     filename = fopen(argv[index], "r"); 
     if(filename == NULL){ 
      printf("The file '%s' did not exist.\n", argv[index]); 
     }else{ 
      while(getline(&line, &len, filename)!=EOF){ 
       if(new_array == NULL){ 
        perror("Failed to allocate"); 
        exit(1); 
       } 

       if(i<=16){ 
        new_array[i] = line; 
        i++; 
       }else{ 
        char** extended_array = extendArray(new_array, 16, countLine); 
        extended_array[i] = line; 
       } 
       printf("%s\n", new_array[i]); 

       countLine++; 
      } 
      //print line result after end of file 
      printf("The file '%s' had %d lines.\n", argv[index], countLine); 
     } 
    } 
} 

utilityFunction.c

#include "utilityFunction.h" 

char **extendArray(char **oldArray, int oldLen, int newLen){ 
    char **newptr = malloc(newLen); 
    if(newptr == NULL){ 
     perror("Failed to allocate"); 
     exit(1); 
    } 
    memcpy(newptr, oldArray, oldLen); 
    free(oldArray); 
    return newptr; 
} 

而一個utilityFunction.h文件

#ifndef UTILITYFUNCTION_H 
#define UTILITYFUNCTION_H 

char **extendArray(char **oldArray, int oldLen, int newLen); 

#endif // UTILITYFUNCTION_H 
+2

這意味着你沒有正確地鏈接你的程序。 – StoryTeller

+0

@StoryTeller可以請你更具體嗎? – HxH

+0

我不行。問題不在於如何編寫程序,而在於它如何構建,並且沒有顯示*那*。 – StoryTeller

回答