我制作文件时遇到错误
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
答案 0 :(得分:0)