Unresolved external errors - what is wrong

Hi, I am rusty and I am trying to do exercises using C++ again. I have separate .cpp, header and main as shown below. Can you kindly help me fix this error that I keep getting. I am using Visual Studio Community. Thank you.
Error:
LNK201 unresolved external symbol WinMain referenced in function
"int_cecl invoke_main(void)"

LNK1121 1 unresolved externals

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
//this is the main.cpp file
#include "exercise1.h"
#include <iostream>
#include <string>

using namespace std;

int main()
{
	Play obj;
	obj.printing();
};

//this is the .cpp (exercise1.cpp):
#include "exercise1.h"

using namespace std;

void Play::PLay()
{

}

int Play::printing()
{
	return 1;
};

//This is the header (exercise1.h):
#ifndef PLAY_H
#define PLAY_H

class Play
{
	private:

	public:
	
		void PLay();

		int printing();

};
#endif 
> LNK201 unresolved external symbol WinMain referenced in function
"int_cecl invoke_main(void)"
WinMain is where GUI programs start.

You need to create a console project to begin with, not a windows/GUI project.
In VS Properties/Configuration Properties/Linker/System and change SubSystem to Console.

PS. Having a class Play and a function PLay is going to cause confusion at some point...
Last edited on
Hello. When I am reading an exercise like this, I could burn the book :/
I understand that it is not always easy for a beginner to "split" a code in multiple file parts with an header file and its declarations - and cpp files out of the main process with some definitions, but what you showed today is just bad...
Nothing is optimized - no constructors with direct parameters, no private members, an included header for nothing...
Respectfully are you sure that you walk on the right way. I know many more interesting tutorials if you want?

PS : you could learn more with a single file :
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
#include <iostream>
// exercise1.h
using namespace std;

class Play
{
public:
    Play();
    int printing();

private:
    const int i = 777;
};

Play::Play()
{
    std::cout << "exercise 1 is running" << std::endl;
}

int Play::printing()
{
    return i;
};
/// <summary>
/// main file
/// </summary>

int main()
{
    Play obj;
    std::cout << obj.printing() << std::endl;

    // or its alternative
    /*
    Play *obj = new Play();
    std::cout << obj->printing() << std::endl;

    delete obj;
    */
};
Last edited on
@Geckoo, the OP's gotta start somewhere.
It is after all labelled exercise1.

If the point of the exercise is to separate into multiple source files, then reducing the fluff to the point of triviality is par for the course.

http://www.sscce.org/
They reduced the problem to it's very essence.
Which is good for everyone.
Topic archived. No new replies allowed.