我试图在线搜索该错误,但所有文章均针对C ++。
这是消息:
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
超级简单的代码,无法理解问题所在
#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
#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
#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
如果我在这里给您文件,可能会更容易些?
无论如何,我很乐意提供有关如何理解问题的提示
你的问题是在函数创建的错字Ë ctionary()。你应该改变它创造了我ctionary()。collect2:错误:ld返回1退出状态在C和C ++中都是相同的问题,通常意味着您有未解析的符号。您的情况就是我之前提到的错字。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句