Linker Errors

Well, I've got linker errors (I think...) and i need some help to solve them. I've written these going by what i have learned from the internet sense my programming teacher is actually learning with us (high school, I'm far ahead of my teacher, he's still cool though so it doesn't matter) so feel free to correct me on standards I've broken so i can learn the right way but anyway, errors first.

I'm using visual c++ 2010 professional and the irrklang library btw.

func.h
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
#include<irrKlang.h>
#include<fstream>
#pragma comment(lib, "irrKlang.lib")

namespace Cory
{
	//control for file in and out functions
	std::ofstream out;//from the program to the file
	std::ifstream in;//from the file to the program

	enum undefKeys {ENTER=13, PAGE_UP=73, HOME=71, END=79, PAGE_DOWN=81, UP_ARROW=72, LEFT_ARROW=75, DOWN_ARROW=80, RIGHT_ARROW=77, F1=59, F2=60, F3=61, F4=62, F5=63, F6=64, F7=65, F8=66, F9=67, F10=68, ESC=27, SPACE=32, BACKSPACE=8};//undefined keys
	enum Colors {Black=0, Blue, Green, Cyan, Red, Purple, Brown, Grey, Dgrey, Lblue, Lgreen, Lcyan, Lred, Pink, Yellow, White};//The values of the color by std

	Colors DEFAULTBGCOLOR = Colors(1);
	Colors DEFAULTTEXTCOLOR = Colors(15);
	irrklang::ik_f32 volumeLevel[] = {.0f, .1f, .2f, .3f, .4f, .5f, .6f, .7f, .8f, .9f, 1.0f};//Volume Levels

	//Use at the beginning of your code
	void RESETTEXTCOLOR();

	void FIXRNG();
	//^^Use at the beginning of your code^^

	//Functions
	std::string convertInt(int number);

	void coutc(std::string output, int TextColor=DEFAULTTEXTCOLOR, int BackgroundColor=DEFAULTBGCOLOR);//colored text out function

	void FailSafe(std::string message = "Major Error shutting down");//when program fail please fail correctly

	void SetDefaultTextColor(int ColorA, int ColorB);//changing the default text color

	void gotoxy(int x,int y);//go to the x and y coordinates given on the program

	int rng(int min, int max, int Randomness=5);//Using a complicated method to provide the best results this outputs a random number

	double rng(double min, double max, int Randomness=5);//Using a complicated method to provide the best results this outputs a random number

	double encrip(double tbe);//tbe is to be encrypted ~ used for encrypting # variables

	double decrip(double tbd);//tbd is to be decrypted ~ used for decrypting the # variables encrypted by the function above

	char getkey();//wait for the user to hit something on the keyboard and return what they hit
	
	std::string GetLine(std::string &Mstr);//get a line from user input

	void pause(std::string message = "Press any key to continue...");//pause system

	void clr();//clear screen

	void SuperOutput(std::string Output, bool clearAfterwards = true);//super special awesome output

	int ChoiceMenu(int NumOfCh, std::string strg[], irrklang::ISoundEngine* Sound, int x=0, int y=0, bool ClearScreen = true, bool ExitAvalable = true);//arrow key choice function with sounds
	int ChoiceMenu(int NumOfCh, std::string strg[], int x=0, int y=0, bool ClearScreen = true, bool ExitAvalable = true);//arrow key choice function without sound
}


me testing it...
main.cpp
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include"Func.h"
#include<string>
using namespace std;

int main()
{
	Cory::RESETTEXTCOLOR();
	Cory::FIXRNG();

	irrklang::ISoundEngine* engine = irrklang::createIrrKlangDevice();

	engine->play2D("test.mp3");

	Cory::coutc(Cory::convertInt(Cory::rng(1,100)),Cory::Lred, Cory::Blue);
	Cory::SetDefaultTextColor(Cory::Red, Cory::Black);
	Cory::coutc(Cory::convertInt(Cory::rng(1,100)));

	Cory::gotoxy(5,5);
	double hold;

	hold = Cory::rng(1.0,2.0, 20);
	Cory::coutc(Cory::convertInt(hold));
	hold=Cory::encrip(hold);
	Cory::coutc(Cory::convertInt(hold));
	hold=Cory::decrip(hold);

	Cory::pause("Ohlolololol");
	Cory::clr();

	string base;

	Cory::GetLine(base);

	Cory::SuperOutput(base, false);

	string cmt[] = {"Work?", "Maybe", "Yes", "No"};

	Cory::ChoiceMenu(3, cmt, engine);

	Cory::ChoiceMenu(3, cmt, 20, 40, false, false);




	Cory::pause();
	engine->stopAllSounds();
	engine->drop();
	return 0;
}


1
2
3
4
5
6
1>main.obj : error LNK2005: "enum Cory::Colors Cory::DEFAULTBGCOLOR" (?DEFAULTBGCOLOR@Cory@@3W4Colors@1@A) already defined in func.obj
1>main.obj : error LNK2005: "enum Cory::Colors Cory::DEFAULTTEXTCOLOR" (?DEFAULTTEXTCOLOR@Cory@@3W4Colors@1@A) already defined in func.obj
1>main.obj : error LNK2005: "float * Cory::volumeLevel" (?volumeLevel@Cory@@3PAMA) already defined in func.obj
1>main.obj : error LNK2005: "class std::basic_ifstream<char,struct std::char_traits<char> > Cory::in" (?in@Cory@@3V?$basic_ifstream@DU?$char_traits@D@std@@@std@@A) already defined in func.obj
1>main.obj : error LNK2005: "class std::basic_ofstream<char,struct std::char_traits<char> > Cory::out" (?out@Cory@@3V?$basic_ofstream@DU?$char_traits@D@std@@@std@@A) already defined in func.obj
1>C:\Users\Cory Powell\documents\visual studio 2010\Projects\functions test\Debug\functions test.exe : fatal error LNK1169: one or more multiply defined symbols found


I'm not gonna bother to add the func.cpp file because that's just how the functions work it shouldn't be the problem...right?

I've never had linker errors before and i wouldn't know what to do with them so I'm hoping you guys can help.
Last edited on
Err... what exactly are these errors?

-Albatross
Err... what exactly are these errors?

-Albatross


Derp....ok my bad xD *face palm*, long night...
Ok so i figured it out. In my func.cpp file i have to have:

1
2
3
4
5
std::ofstream Cory::out;//from the program to the file
std::ifstream Cory::in;//from the file to the program
Cory::Colors Cory::DEFAULTBGCOLOR = Cory::Colors(1);
Cory::Colors Cory::DEFAULTTEXTCOLOR = Cory::Colors(15);
irrklang::ik_f32 volumeLevel[] = {.0f, .1f, .2f, .3f, .4f, .5f, .6f, .7f, .8f, .9f, 1.0f};//Volume Levels 


and in my func.h i have to have:

1
2
3
4
5
6
7
8
9
extern std::ofstream out;//from the program to the file
	extern std::ifstream in;//from the file to the program

	enum undefKeys {ENTER=13, PAGE_UP=73, HOME=71, END=79, PAGE_DOWN=81, UP_ARROW=72, LEFT_ARROW=75, DOWN_ARROW=80, RIGHT_ARROW=77, F1=59, F2=60, F3=61, F4=62, F5=63, F6=64, F7=65, F8=66, F9=67, F10=68, ESC=27, SPACE=32, BACKSPACE=8};//undefined keys
	enum Colors {Black=0, Blue, Green, Cyan, Red, Purple, Brown, Grey, Dgrey, Lblue, Lgreen, Lcyan, Lred, Pink, Yellow, White};//The values of the color by std

	extern Colors DEFAULTBGCOLOR;
	extern Colors DEFAULTTEXTCOLOR;
	extern irrklang::ik_f32 volumeLevel[];
Topic archived. No new replies allowed.