Jump to content
  • Advertisement
Sign in to follow this  
sotsilent

Confusing Linker Errors

This topic is 3922 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was trying to make a little program that parses files into variable/value pairs and stores them in a map. The compiler (Visual C++ Express Edition) is returning these linker errors, and I have no idea what is wrong:
1>Parse.obj : error LNK2005: "class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > * __cdecl ParseFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?ParseFile@@YAPAV?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) already defined in main.obj
1>Parse.obj : error LNK2005: "class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > * __cdecl ParseFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?ParseFile@@$$FYAPAV?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) already defined in main.obj
1>C:\Documents and Settings\sotsilent\Desktop\Test Programming\Parser\Debug\Parser.exe : fatal error LNK1169: one or more multiply defined symbols found

Here's the code:
//Parse.cpp - Implementation
//Sheldon Bachstein
//December 30, 2007

//Using ifstreams
#include<fstream>
using std::ifstream;

//Using strings and maps
#include<string>
#include<map>
using std::map;
using std::string;

	map<string, string>* ParseFile(string file)
	{
		ifstream f(file.c_str());		//Open file for input.
		if(!f)							//If not ready to read...
			return NULL;				//	return null.

		map<string, string> *result = new map<string, string>;

		char c;
		string token;
		string first;
		bool isFirst = true;
		bool quotes = false;

		while(f.good())
		{
			f.get(c);					//Get next char

			switch(c)
			{
			case ' ':
				if(quotes)
					token += c;			//If inside quotes, keep spaces
				break;
			case '=':
				if(!isFirst)	
					return NULL;		//This shouldn't happen
				first = token;
				token.clear();
				isFirst = false;
				break;
			case '\"':
				if(quotes)
					quotes = false;
				else
					quotes = true;
				break;
			case '\n':
				if(isFirst)
					return NULL;		//Newlines should only be found after values.
				//*result[first] = token;
				result->insert(std::make_pair(first, token));
				token.clear();
				first.clear();
				break;
			case '[':
				f.ignore(255, '\n');
				break;
			default:
				token += c;
				break;
			}
		}
			return result;				//Return result.
	}

Can anyone please explain what's wrong? I have absolutely no idea. Any help is appreciated a lot.

Share this post


Link to post
Share on other sites
Advertisement
I bet you're using VC++.

Try deleting the debug file.

Try making sure you don't include that file more than once.

If all else fails, surround your code with:
#ifndef WHATEVER
#define WHATEVER

// Your code here

#endif

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!