2016-11-06 2 views
0

traf ich einen Fehler, wenn ich Datei machenWas bedeutet "Undefinierte Symbole für Architektur x86_64:" in c?

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 

Ich habe schaute sich um für ein paar Antworten, aber keine wirklich Sinn für mich. Ich habe keine Ahnung, was mit meinem Code nicht stimmt. Mein Code wie folgt zusammen:

#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; 
} 

Und eine utilityFunction.h Datei

#ifndef UTILITYFUNCTION_H 
#define UTILITYFUNCTION_H 

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

#endif // UTILITYFUNCTION_H 
+2

Es bedeutet, dass Sie nicht Ihr Programm hat verknüpfen richtig. – StoryTeller

+0

@StoryTeller könnten Sie bitte genauer sein? – HxH

+0

kann ich nicht. Das Problem liegt nicht darin, wie das Programm geschrieben wurde, sondern wie es erstellt wurde, und Sie haben * das * nicht angezeigt. – StoryTeller

Antwort

Verwandte Themen