Próbowałem wyszukać ten błąd w Internecie, ale wszystkie posty dotyczą C++.C compile: collect2: error: ld zwrócony 1 status wyjścia
Jest to przesłanie:
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
bardzo prosty kod i nie może zrozumieć, w czym 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;
...
teraz jest to nagłówek dict.h
#ifndef _DICT_H_
#define _DICT_H_
#include "hash.h"
pHash CreateDictionary();
...
#endif
i tutaj jest 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;
}
i jeśli chcesz sprawdzić 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
Może łatwiej będzie jeśli dam ci pliki tutaj?
jakikolwiek sposób, będę szczęśliwy dla wskazówek, jak zrozumieć problem
To ten sam problem w C i C++, linker nie może znaleźć 'CreateDictionary'. W twoim przypadku jest tak prawdopodobnie dlatego, że zdefiniowałeś 'CreateDectionary' zamiast ... – Leiaz
czy możesz wytłumaczyć? co zdefiniowałem zamiast czego? – JohnnyF
Masz literówkę. Słownik nie D ** e ** cionowy. – Leiaz