c - "Undefined symbols for architecture x86_64:"在c中是什么意思?

标签 c gcc

我在制作文件时遇到错误

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

最佳答案

可能是您正在导入 header ,但它没有链接到正确的库。

这个问题和答案可能会帮助您回答。

Undefined symbols for architecture armv7

关于c - "Undefined symbols for architecture x86_64:"在c中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40447002/

相关文章:

c - gdb 在 Centos 上找不到调试信息

ubuntu : vmlinuz or crash file not a supported file format 上的崩溃转储

c - 用 C/C++ 编写 Web 服务

c - AVCodec PTS 时间戳不从 0 开始

c++ - 如何在 64 位 Windows 7 上使用 cygwin 从 C++ 生成 Java VM?

c++ - 禁用不兼容选项的 gcc 警告

c - 这两个声明之间有什么区别吗?

C++语法歧义

c++ - 在 C++ 中禁用系统调用

c++ - gcc 4.8.1 默认启用 sse 吗?