Hello. I've recently been trying to take a giant mess of code that I'm working on and split it into small, more convenient files by adding various .h and .cpp files to a C::B project. I've read a little on header guards and preprocessor directives and understand what the multiple definition error is, but I'm having trouble actually finding where I've defined a function more than once. Anyway, I have 7 files, which I will detail below.
main.cpp, contains most of my code and makes use of code in all headers and .cpp files; has the following at the top
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <windows.h>
#include <wchar.h>
#ifndef CONCOL_H_INCLUDED
#include "concol.h"
#endif
#ifndef SOMEFUNCTIONS_H_INCLUDED
#include "somefunctions.h"
#endif
#ifndef ITEM_H_INCLUDED
#include "item.h"
#endif
using namespace std;
|
globals.cpp, contains a bunch of global variables that all files use; has this at the top
1 2 3 4
|
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
|
concol.h, code that I found here:
http://www.cplusplus.com/articles/2ywTURfi/ that allows me to change output color; it contains functions textcolor() and backcolor() and looks something like this:
1 2 3 4 5 6 7 8 9 10
|
#ifndef CONCOL_H_INCLUDED
#define CONCOL_H_INCLUDED
#ifndef _INC_WINDOWS
#include<windows.h>
#endif /*_INC_WINDOWS*/
//a few variable definitions
//prototypes for textcolor() and backcolor()
//definitions of textcolor() and backcolor()
#endif // CONCOL_H_INCLUDED
|
item.h, a header for a class called "item"; looks like this:
1 2 3 4 5 6 7 8 9 10 11 12
|
#include <cstdlib>
#include <iostream>
#include <string.h>
#ifndef ITEM_H_INCLUDED
#define ITEM_H_INCLUDED
using namespace std;
//declare the class and its members here
#endif // ITEM_H_INCLUDED
|
item.cpp, contains the definitions of the member functions in class "item", has this at the top:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <windows.h>
#include <wchar.h>
#ifndef CONCOL_H_INCLUDED
#include "concol.h"
#endif
#ifndef SOMEFUNCTIONS_H_INCLUDED
#include "somefunctions.h"
#endif
#ifndef ITEM_H_INCLUDED
#include "item.h"
#endif
using namespace std;
|
somefunctions.h, a header containing the function prototypes for most of the functions used in other files, looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <cstdlib>
#include <iostream>
#include <string.h>
#ifndef CONCOL_H_INCLUDED
#include "concol.h"
#endif
#ifndef ITEM_H_INCLUDED
#include "item.h"
#endif
using namespace std;
#ifndef SOMEFUNCTIONS_H_INCLUDED
#define SOMEFUNCTIONS_H_INCLUDED
//here are all of the prototypes
#endif // SOMEFUNCTIONS_H_INCLUDED
|
somefunctions.cpp, contains the definitions of all the functions, has this at the top:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <windows.h>
#include <wchar.h>
#ifndef CONCOL_H_INCLUDED
#include "concol.h"
#endif
#ifndef SOMEFUNCTIONS_H_INCLUDED
#include "somefunctions.h"
#endif
#ifndef ITEM_H_INCLUDED
#include "item.h"
#endif
using namespace std;
|
I tried to include the guards in the .cpp files so that no header would be included more than once, but when I attempt to compile this, I get the following error:
multiple definition of 'textcolor()'
Apparently this was defined in a function called Z9textcolorv (which I didn't create, but is instead included in a file called char_traits.h). The same thing happens for backcolor(), but not for another function that is defined in concol.h, setcolor. I suspect that the problem is my file linking. Can anyone help? Thanks.