C编译:collect2:错误:ld返回1退出状态 [英] C compile : collect2: error: ld returned 1 exit status

查看:2832
本文介绍了C编译:collect2:错误:ld返回1退出状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在线搜索该bug,但所有帖子都是为C ++。

I tried to search for that bug online but all the posts are for C++.

这是消息:


test1.o:在函数 ReadDictionary':
/home/johnny/Desktop/haggai/test1.c:13:undefined reference to CreateDictionary'
collect2:error:ld returned 1退出状态
make:*** [test1]错误1

test1.o: In function ReadDictionary': /home/johnny/Desktop/haggai/test1.c:13: undefined reference toCreateDictionary' collect2: error: ld returned 1 exit status make: *** [test1] Error 1

超级简单代码,无法解决问题

super simple code and can't understand what's the problem

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dict.h"
#include "hash.h"


pHash ReadDictionary() {
    /* This function reads a dictionary line by line from the standard input. */
    pHash dictionary;
    char entryLine[100] = "";
    char *word, *translation;

    dictionary = CreateDictionary();
    while (scanf("%s", entryLine) == 1) { // Not EOF
        word = strtok(entryLine, "=");
        translation = strtok(NULL, "=");
        AddTranslation(dictionary, word, translation);
    }
    return dictionary;
}

int main() {
    pHash dicti;
...

现在是标题dict.h

now this is the header dict.h

#ifndef _DICT_H_
#define _DICT_H_

#include "hash.h"

pHash CreateDictionary();
...

#endif

dict.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hash.h"
#include "dict.h"


pHash CreateDectionary()
{
    pHash newDict;
    newDict= HashCreate(650, HashWord, PrintEntry, CompareWords, GetEntryKey, DestroyEntry);
    return newDict;
}

如果您想检查hash.h

and if you wanna check hash.h

#ifndef _HASH_H_
#define _HASH_H_

//type defintions//
typedef enum {FAIL = 0, SUCCESS} Result;
typedef enum {SAME = 0, DIFFERENT} CompResult;

typedef struct _Hash Hash, *pHash;

typedef void* pElement;
typedef void* pKey;

//function types//
typedef int (*HashFunc) (pKey key, int size);
typedef Result (*PrintFunc) (pElement element);
typedef CompResult (*CompareFunc) (pKey key1, pKey key2);
typedef pKey (*GetKeyFunc) (pElement element);
typedef void (*DestroyFunc)(pElement element);
...

//interface functions//

#endif

也许如果我在这里给你的文件会更容易吗?

Maybe it will be easier if I give you the files here?

无论如何,我会很高兴提示如何理解问题

Any way, I will be happy for tips on how to understand the problem

推荐答案

您的问题是函数CreateD e 应将其更改为CreateD i ctionary()。
collect2:error:ld返回1退出状态是C和C ++中的相同问题,通常它意味着您有未解析的符号。在你的情况是我提到的错字。

Your problem is the typo in the function CreateDectionary().You should change it to CreateDictionary(). collect2: error: ld returned 1 exit status is the same problem in both C and C++, usually it means that you have unresolved symbols. In your case is the typo that i mentioned before.

这篇关于C编译:collect2:错误:ld返回1退出状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆