Unresolved External Symbol

Hey, my code is rather short, but when I compile it, I get 1 error about an unresolved external symbol, it probably has something to do with the file processing. . .

Just a basic keylogger using SDL


Keylogger.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef KEYLOGGER_H
#define KEYLOGGER_H


#include <fstream>
#include <SDL.h>

using namespace std;

class Keylogger
{
public:

	Keylogger();
	~Keylogger();
	void logKey(const char loggedCharacter);
	void parseKey(Uint16 suppliedChar);

private:
	ofstream file;
};

#endif 


Keylogger.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "Keylogger.h"

Keylogger::Keylogger()
{
	file.open("keylogger.txt");
}

Keylogger::~Keylogger()
{
	file.close();
}

void Keylogger::logKey(const char loggedKey)
{
	file << loggedKey;
}

void Keylogger::parseKey(Uint16 suppliedKey)
{
	switch (suppliedKey)
	{
	case SDLK_a:
		logKey('a');
		break;
	case SDLK_b:
		logKey('b');
		break;
	case SDLK_c:
		logKey('c');
		break;
	case SDLK_d:
		logKey('d');
		break;
	case SDLK_e:
		logKey('e');
		break;
	case SDLK_f:
		logKey('f');
		break;
	case SDLK_g:
		logKey('g');
		break;
	case SDLK_h:
		logKey('h');
		break;
	case SDLK_i:
		logKey('i');
		break;
	case SDLK_j:
		logKey('j');
		break;
	case SDLK_k:
		logKey('k');
		break;
	case SDLK_l:
		logKey('l');
		break;
	case SDLK_m:
		logKey('m');
		break;
	case SDLK_n:
		logKey('n');
		break;
	case SDLK_o:
		logKey('o');
		break;
	case SDLK_p:
		logKey('p');
		break;
	case SDLK_q:
		logKey('q');
		break;
	case SDLK_r:
		logKey('r');
		break;
	case SDLK_s:
		logKey('s');
		break;
	case SDLK_t:
		logKey('t');
		break;
	case SDLK_u:
		logKey('u');
		break;
	case SDLK_v:
		logKey('v');
		break;
	case SDLK_w:
		logKey('w');
		break;
	case SDLK_x:
		logKey('x');
		break;
	case SDLK_y:
		logKey('y');
		break;
	case SDLK_z:
		logKey('z');
		break;
	}
	
}


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
#include "Keylogger.h"

int main(int argc, char **argsv)
{
	if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
		return 1;

	SDL_Event Event;
	Keylogger keylogger;

	enum class Status
	{
		CONTINUE,
		COMPLETE
	} status = Status::CONTINUE;

	while (status != Status::COMPLETE)
	{
		while (SDL_PollEvent(&Event))
		{
			switch (Event.type)
			{
			case SDL_KEYDOWN:
				keylogger.parseKey(Event.key.keysym.sym);
			}
		}
	}

	return 0;

	SDL_Quit();
}


Errors

Error 1 error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: char const & __thiscall std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >::operator*(void)const " (??D?$_String_const_iterator@V?$_String_val@U?$_Simple_types@D@std@@@std@@@std@@QBEABDXZ) C:\Users\avie\documents\visual studio 2013\Projects\Practice\Practice\Keylogger.obj Practice


Any ideas?
Make sure you are letting visual studio know that Main.cpp should be compiled along with Keylogger.cpp. If you are compiling via console/terminal, then your compiling command should be something along the lines of:

g++ -pedantic Main.cpp Keylogger.cpp -Wall -Wextra -Werrors -I/location/of/SDL.h -lSDL -o keylogger

Having a second look at your code, this line might be what is causing the problem:
int main(int argc, char **argsv)
Last edited on
Well, it's funny because even,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <SDL.h>
#include <fstream>
#include <iostream>

using namespace std;

int main(int argc, char** argsv)
{
	if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
	{
		return 1;
	}

	std::ofstream file;

	file.open("text.txt");

	file << "hey";


	SDL_Quit();

	return 0;
}


throws the same error (which doesn't have any keylogger.cpp/h)

It's also not the main function, as that is how you write main with command line arguments/for SDL.

When I take away the file declarations, it compiles fine. . . Is there some sort of missing component when trying to compile the headers that are used to create/use files?
Topic archived. No new replies allowed.