Getting two link errors with my code provided below They are being generated by lines 38-46 I believe. I can't seem to find an issue...

1>AoE2Wide.obj : error LNK2020: unresolved token (0A000340) "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > AoE2Wide::Program::_gameDirectory" (?_gameDirectory@Program@AoE2Wide@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A)
1>AoE2Wide.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > AoE2Wide::Program::_gameDirectory" (?_gameDirectory@Program@AoE2Wide@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A)
1>C:\Users\Public\Documents\AOC Source\C++\AoE2Wide\Debug\AoE2Wide.exe : fatal error LNK1120: 2 unresolved externals

// AoE2Wide.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "AoE2Wide.h"
#include "Program.h"
#include "UserFeedback.h"
#include <iostream>
#include <string>
#include <direct.h> // used for game directory finding
//#using <mscorlib.dll>

void Go(void);
std::string FindGameDirectory(void);

int main(int argc, char* argv[])
{
	try
	{
		Go();
	}
	catch (Exception ^e)
	{
		AoE2Wide::UserFeedback::Error(e);
	}
	AoE2Wide::UserFeedback::Close();
} 

void Go(void)
{
	using namespace AoE2Wide;
	// call function above to find the game directory and store it in _gameDirectory
	Program::_gameDirectory = FindGameDirectory();
}

std::string FindGameDirectory(void)
{
	using namespace std;
	AoE2Wide::UserFeedback::Trace("Locating game main folder...");
	char * buffer;
	if( (buffer = _getcwd( NULL, 0)) == NULL)
		perror( "_getcwd error");
	char language[500];
	strcpy_s(language, buffer);
	strcat_s(language, "\\language_x1.dll");
	while (strlen(language) == 0)
	{
		throw gcnew AoE2Wide::FatalError("Cannot locate the proper directory.  Please run the patch from the correct directory in the Age of Empires 2 Dirctory");
	}
	AoE2Wide::UserFeedback::Trace("Located the correct folder!");
	return buffer;
}

Here is the header file also.

// Program class

#include <iostream>
#include <string>

namespace AoE2Wide
{
	class Program
	{
		public:
			 static std::string _orgDrsPath;
			 static std::string _orgX1DrsPath;
			 static std::string _orgExePath;
			 static std::string _gameDirectory;
			 static const bool skipExistingFiles = false;

	};
};

I am defining them later on, is this not allowed?

I am defining them later on

Apparently you're not doing it correctly, because the linker doesn't see them.

So i moved it outside the Go() function and put a std::string in front of it and now it works.

It was complaining about the scope. You can't declare static variables in a scope?

You can't declare static variables in a scope?

Do you have a book on C++? I get the distinct impression that you're guessing and going on intuition for the most part when writing this program.

I have a C++ book and read about 85% of it. I am re-coding this from scratch now, but obv some of the factors don't translate directly over. Now that u reminded me I had the same issue with another program that I made, i made the same mistake 2 times, and it mostly makes sense, I just wanted to verify it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.