They always find their way into my programs!
This time I'm getting errors when I try to include my header file in two different files of the same project. The only way it works is if instead of #including "consoletools.h", I #include "consoletools.cpp" in one of the two files. I'm also getting errors when i make a test program for the sole purpose of using the functions. The .h contains just the function definitions, the .cpp has the actual code for the functions.
The consoletools.h file:
The test file:Code:#include <windows.h> #include <iostream> using namespace std; #ifndef CONSOLETOOLS_H #define CONSOLETOOLS_H void setTitle(char title[]); void cls(); void replaceChar(char newChar, int x, int y); void color(string text, string color); void toggleCursor(); void pause(); char getYorN(); #endif
The linker errors:Code:#include "consoletools.h" #include <iostream> using namespace std; int main() { string x; while (true) { cin >> x; cin.ignore(); setTitle("Test program"); color("Color\n",x); pause(); cls(); } }
I'm sure the answer is obvious... but I can't seem to point it out. I hate linker errors!Code:[Linker error] undefined reference to `setTitle(char*)' [Linker error] undefined reference to `color(std::string, std::string)' [Linker error] undefined reference to `pause()' [Linker error] undefined reference to `cls()' ld returned 1 exit status![]()



LinkBack URL
About LinkBacks



