Data structure gives error LNK2001

Greetings,

I'm having issues with constructing structures. I am using the SFML library, but that doesn't seem to be the issue. This is the code that cause me problems:

1
2
3
4
5
6
struct main_variables{
public:
	static sf::RenderWindow main_variables::application;
	static int main_variables::seconds;
	static sf::Sound main_variables::clock_ticking_1;
};


Output:
1>main.obj : error LNK2001: unresolved external symbol "public: static class sf::Sound main_variables::clock_ticking_1" (?clock_ticking_1@main_variables@@2VSound@sf@@A)
1>main.obj : error LNK2001: unresolved external symbol "public: static class sf::RenderWindow main_variables::application" (?application@main_variables@@2VRenderWindow@sf@@A)
1>main.obj : error LNK2001: unresolved external symbol "public: static int main_variables::seconds" (?seconds@main_variables@@2HA)

I tried looking up this error (LNK2001: unresolved external symbol) on Google, and it seems to be a common issue. However, that didn't help me, and now I am stuck :(

Any help will be appreciated.
closed account (Dy7SLyTq)
it looks like you arent linking to the libraries right. did you do them in the correct order?
Where do you initialize these static variables?
@DTSCode: They should be linked in the right order...
@jlb:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <SFML\Audio.hpp>
#include <SFML\System.hpp>
using namespace std;

struct main_variables{
public:
	static sf::Sound main_variables::clock_ticking_1;
	static sf::RenderWindow main_variables::application;
	static int main_variables::seconds;
	
};

int main(){
// main variables
	main_variables m;
	m.seconds = 0;
// ...
}
This is all inside main.cpp. At the moment there are no other cpp, or h files.
closed account (Dy7SLyTq)
theyre static so i think you have to initialize them in the struct
I have fiddled around a bit more with the code I had, and removed the static keyword from the initializations of the 3 variables in the structure main_variables. However, this gives me a SFML related error. I will ask for help on the SFML forum.
Topic archived. No new replies allowed.