I tried to search for that bug online but all the posts are for C++.
我试着在网上搜索那个bug,但是所有的帖子都是为了c++。
This is the message:
这是信息:
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 1test1。o: In function ReadDictionary: /home/ johnny/desktop/haggai/test1。c:13: undefined reference toCreateDictionary' collect2: error: ld返回1退出状态:*** [test1]错误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;
...
now this is the header dict.h
这是标题。
#ifndef _DICT_H_
#define _DICT_H_
#include "hash.h"
pHash CreateDictionary();
...
#endif
and here is the dict.c
这是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;
}
and if you wanna check hash.h
如果你想检查哈希。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
无论如何,我都会为如何理解这个问题而高兴。
6 个解决方案
#1
13
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.
您的问题是函数CreateDectionary()中的typo。您应该将它改为CreateDictionary()。collect2:错误:ld返回1退出状态在C和c++中都是相同的问题,通常意味着您有未解决的符号。在你的例子中是我之前提到的打字错误。
#2
1
sometimes this error came beacause failed to compile in middlest of any build. The best way to try is by doing make clean and again make the whole code .
有时这个错误是由于编译失败而导致的。最好的方法就是把代码做干净,然后再做完整的代码。
#3
0
When compiling your program, you need to include dict.c as well, eg:
在编译程序时,您需要包括dict.c。
gcc -o test1 test1.c dict.c
gcc - o test1 test1。c dict.c
Plus you have a typo in dict.c definition of CreateDictionary
, it says CreateDectionary
(e
instead of i
)
另外,在CreateDictionary的dict.c定义中有一个错误,它说CreateDectionary (e而不是i)
#4
0
I got this problem, and tried many ways to solve it. Finally, it turned out that make clean
and make
again solved it. The reason is: I got the source code together with object files compiled previously with an old gcc version. When my newer gcc version wants to link that old object files, it can't resolve some function in there. It happens to me several times that the source code distributors do not clean up before packing, so a make clean
saved the day.
我遇到了这个问题,并尝试了很多方法来解决它。最后,结果证明是干净的,并再次解决了它。原因是:我把源代码和以前用gcc版本编译过的对象文件一起得到了。当我的新gcc版本想要链接旧的对象文件时,它不能解析其中的某个函数。在包装之前,我经常会遇到一些源代码分销商不清理的事情,因此,一个干净的地方就可以节省一天的时间。
#5
0
generally this problem occurred when we have called a function which has not been define in the program file, so to sort out this problem check whether have you called such function which has not been define in the program file.
通常这个问题发生在我们调用了一个没有在程序文件中定义的函数时,为了解决这个问题,你是否调用了这个在程序文件中没有定义的函数。
#6
-2
- Go to Advanced System Settings in the computer properties
- 进入计算机属性的高级系统设置。
- Click on Advanced
- 点击高级
- Click for the environment variable
- 单击环境变量。
- Choose the path option
- 选择的路径选择
- Change the path option to bin folder of dev c
- 将路径选项更改为dev c的bin文件夹。
- Apply and save it
- 应用和保存它
- Now resave the code in the bin folder in developer c
- 现在将代码保存在开发人员c的bin文件夹中。
#1
13
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.
您的问题是函数CreateDectionary()中的typo。您应该将它改为CreateDictionary()。collect2:错误:ld返回1退出状态在C和c++中都是相同的问题,通常意味着您有未解决的符号。在你的例子中是我之前提到的打字错误。
#2
1
sometimes this error came beacause failed to compile in middlest of any build. The best way to try is by doing make clean and again make the whole code .
有时这个错误是由于编译失败而导致的。最好的方法就是把代码做干净,然后再做完整的代码。
#3
0
When compiling your program, you need to include dict.c as well, eg:
在编译程序时,您需要包括dict.c。
gcc -o test1 test1.c dict.c
gcc - o test1 test1。c dict.c
Plus you have a typo in dict.c definition of CreateDictionary
, it says CreateDectionary
(e
instead of i
)
另外,在CreateDictionary的dict.c定义中有一个错误,它说CreateDectionary (e而不是i)
#4
0
I got this problem, and tried many ways to solve it. Finally, it turned out that make clean
and make
again solved it. The reason is: I got the source code together with object files compiled previously with an old gcc version. When my newer gcc version wants to link that old object files, it can't resolve some function in there. It happens to me several times that the source code distributors do not clean up before packing, so a make clean
saved the day.
我遇到了这个问题,并尝试了很多方法来解决它。最后,结果证明是干净的,并再次解决了它。原因是:我把源代码和以前用gcc版本编译过的对象文件一起得到了。当我的新gcc版本想要链接旧的对象文件时,它不能解析其中的某个函数。在包装之前,我经常会遇到一些源代码分销商不清理的事情,因此,一个干净的地方就可以节省一天的时间。
#5
0
generally this problem occurred when we have called a function which has not been define in the program file, so to sort out this problem check whether have you called such function which has not been define in the program file.
通常这个问题发生在我们调用了一个没有在程序文件中定义的函数时,为了解决这个问题,你是否调用了这个在程序文件中没有定义的函数。
#6
-2
- Go to Advanced System Settings in the computer properties
- 进入计算机属性的高级系统设置。
- Click on Advanced
- 点击高级
- Click for the environment variable
- 单击环境变量。
- Choose the path option
- 选择的路径选择
- Change the path option to bin folder of dev c
- 将路径选项更改为dev c的bin文件夹。
- Apply and save it
- 应用和保存它
- Now resave the code in the bin folder in developer c
- 现在将代码保存在开发人员c的bin文件夹中。