c++ - Undefined reference error when compiling with g++ compiler in cygwin -
I am just starting to work on a project for the class and I am getting an error that I am unsure about How to fix it I will do our best to provide all the necessary details, but if you need more information, please tell me this project is to create a simple hash function and I am getting a linker error while trying to compile. When compiling, I will get all my code and error. I have taken the last two programming classes, but it was a long time ago and at this time I am out of practice so it can be a clear error. Ignore all the commented code in the hash because it is just the function definitions that my teacher has provided that I have not yet implemented. He specifically requested that we put our Hashing function in my separate file. I should also specify that I am using a Windows machine along with Signin 64 to compile my code.
#ifndef __HASH_H #define___HASH_H #include & lt; String & gt; # Include & lt; List & gt; Using std :: string; Using the Std :: list; Class hash {public: zero extract (string); // Remove the hash key from the table // zero print (); // Print the entire hash table zero process file (string); // Add keys in open file and hash table // tool search (string); // search for a key in the hash table // zero output (string); // Print the entire hash table in a file // zero printstats (); // Print Data Personal: // HASH_TABLE_SIZE G ++ // list & lt; String & gt; Should be defined through the -D option. Hashtable [HASH_TABLE_SIZE]; & Lt; String & gt; Hashtable [100]; Int Collision; Longest list; Double aval lang; Int HF (string); // insert the hash function zero (string); // Additional variables / put / down tasks / do not change anything above! }; #endif
hash.cpp:
#include "hash.h" void hash :: remove (string string_to_remove) {int index = hf (string_to_remove )); (List & lt; string & gt; :: iterator iter = hashTable [index] .begin (); iter! = Hash tabbed [index] .end (); iter ++) {if (* iter == string_to_remove) hashTable [ Index] .REZ (ITER); }} Zero hash :: insertion (string string_to_d) {int index = hf (string_to_add); Hashtable [index] .push_back (string_to_add); } Zero hash :: process file (string file_name) {insert (file_name); }
hash_function.cpp
#include "hash.h" int hash :: hf (string input) {int sum = 0; For (Int i = 0; I <5; i ++) Yoga + = (int) input [i]; Cout & lt; & Lt; Amount% 100 & lt; & Lt; Endl; Return [amount% 100 / * HASH_TABLE_SIZE * /]; }
Compiler error:
$ g ++ hash_function. Cpp testmain.cpp hash CPP -o test /tmp/cc42z5XM.o:hash.cpp: (.text + 0x32): `Hush :: hf (std :: string) '/tmp/cc42z5XM.o:hash.cpp: Undefined context for ((.text + 0x32): Transfer chopping to slip: R_X86_64_PC32` hash against undefined symbol: hf (std :: string) '/tmp/cc42z5XM.o:hash.cpp:(.text+ 0x13c): Undefined reference to 'hash :: hf (std :: string)' /tmp/cc42z5XM.o: hash.cpp: (text + 0x13c): the transfer is truncated to fit: R_X86_64_PC32 unchanged symbol Against 'hash :: HF (study :: string)' collection 2: Uti LD has 1 returned exit status
Comments
Post a Comment