Ç编译:collect2:错误:LD返回1退出状态 [英] C compile : collect2: error: ld returned 1 exit status
问题描述
我试图寻找这个bug在线,但所有的职位都是C ++。
I tried to search for that bug online but all the posts are for C++.
这如果MSG
test1.o: In function `ReadDictionary':
/home/johnny/Desktop/haggai/test1.c:13: undefined reference to `CreateDictionary'
collect2: error: ld returned 1 exit status
make: *** [test1] Error 1
超级简单code和无法理解什么问题。
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
and here is the 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
推荐答案
您的问题是在电子 ctionary()创建的函数,你应该将其更改为错字创建 I ctionary()。
collect2:错误: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.
这篇关于Ç编译:collect2:错误:LD返回1退出状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!