Using static const int as member variables of a class

Hey,
I am using GLFW for my windowing & input system. I want to define each GLFW_KEY as a static const int in my KeyCode class. (Note that GLFW_KEY_<id> is an #define.

For example, in KeyCode.h:
1
2
3
4
5
6
7
#include "CoreAPI.h"

class CORE_API KeyCode
{
public:
	static const int MYKEY;
};



And KeyCode.cpp

1
2
3
4
#include "KeyCode.h"
#include <GLFW/glfw3.h>

const int KeyCode::MYKEY = GLFW_KEY_0;


Notice that CORE_API is set to dllexport when building the dll and dllimport when using the dll (from say, my exe app).

Now in my main exe app I have the following code (Main.cpp) :

1
2
3
4
#include "KeyCode.h"
#include <stdio.h>

printf("Key = %d\n",KeyCode::MYKEY)


I get the following error:
Error	LNK2001	unresolved external symbol "public: static int const KeyCode::MYKEY" (?MYKEY@KeyCode@@2HB)	TestExe	C:\Dev\vici\projects\vs2015\Vici2\TestExe\Main.obj	1

Any idea why this is happening? Been at this for about 2 hours now trying all sorts of different examples and I can't seem to find a solution.

I really need to define the consts in the CPP file otherwise I would have to include <glfw> in the KeyCode.h file and define the keycodes there. This will result in other errors when projects cant find (havn't set the include path) for the GLFW headers.

Thanks,
Nick.

EDIT:
Just incase it is not clear,
KeyCode is built into the Vici2.dll
And my TestExe.exe project is referencing it.

I know that the libraries are linking because it uses other components of the Vici2 library and when I comment out the printf("Key = %d\n",KeyCode::MYKEY) line it compiles fine and executes.

I've also tried cleaning and rebuilding project and still no luck
Last edited on
Topic archived. No new replies allowed.