Jump to content

SDL Open GL C++ Entry point fatal error LNK1561 Visual Studio 2017

Guest

TL;DR:
I can't get Visual Studio 2017 to compile because it says it can't find the entry point to the program. 

 

Full Story:

I looked for solutions on google and tried changing the arguments, and clearing my arguments from my 

int main() 

in my main.cpp but I get this 

Quote

1>LINK : fatal error LNK1561: entry point must be defined

I even right clicked my project name -> properties -> Linker -> System -> SubSystem
And changed it to many different options but compiling isn't working. 

How do I redefine an entry point? (I've had this issue several times in the past without finding a solution. I remember why I stopped using C++ now....)
I'm willing to try other compilers. I attempted using Code::Blocks with it's anti-retina burning technology, but it told me my compiler doesn't work. I did the full installation. I also tried Dev-C++ but it also had errors. 

Project files:

Spoiler

Depends on:

Spoiler

All 64 bit
Open GL, SDL, and Open GL mathematics

Quote

glew-2.1.0-32

Quote

glm-0.9.9-a2

Quote

SDL2-devel-2.0.8

Links:

 

main.cpp

Spoiler


#include <iostream>
#include <GL/glew.h>
#include "display.h"

int main(int argc, char** argv) 
{
	short hello;
	
	Display display(800, 600, "WindowThingysaf");
	
	while (!display.IsClosed())
	{
		glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT);

		display.Update();
	}
	
	std::cin >> hello;
	return 0;
}

 

display.h

Spoiler


#ifndef Display_H
#define Display_H

#include<string>
#include <SDL2/SDL.h>

class Display
{
	public:
		Display(int width, int height, const std::string& title);

		void Update();
		bool IsClosed();

		virtual ~Display();
	
	protected:

	private:
		Display(const Display& other) {}
		Display& operator=(const Display& other) {}

		SDL_Window* m_window;
		SDL_GLContext m_glContext;
		bool m_isClosed;

};

#endif

 

display.cpp

Spoiler


#include "display.h"
#include <iostream>
#include <GL/glew.h>

Display::Display(int width, int height, const std::string& title)
{
	std::cout << "Construct!" << std::endl;

	SDL_Init(SDL_INIT_EVERYTHING);

	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	m_window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
	m_glContext = SDL_GL_CreateContext(m_window);

	GLenum status = glewInit();
	if (status != GLEW_OK)
	{
		std::cerr << "Glew failed to initialize" << std::endl;
	}
	m_isClosed = false;
}

Display::~Display()
{
	std::cout << "Destruct!" << std::endl;
	SDL_GL_DeleteContext(m_glContext);
	SDL_GL_DeleteContext(m_window);
	SDL_Quit();
}

bool Display::IsClosed() 
{
	return m_isClosed;
}

void Display::Update()
{
	SDL_GL_SwapWindow(m_window);

	SDL_Event e;

	while (SDL_PollEvent(&e)) 
	{
		if (e.type == SDL_QUIT)
		{
			m_isClosed = true;
		}
	}

}

 

Following Guide:

Spoiler

Lessons 1, 1.5 Windows, 2
 

Spoiler

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

This is a problem with the SDL library. SDL defines its own entry point so must either tell VS where that entry point is by setting the subsystem to console then in project properties > linker > advanced, setting the entry point to whatever SDL calls its main function (I can't remember the name sorry.) Or add a define for SDL_MAIN_HANDLED before #including SDL.h to tell SDL you want to use your own entry point.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Sorry for the delayed reply. I wanted to try everything I could before replying to you. 

15 minutes ago, fizzlesticks said:

This is a problem with the SDL library. SDL defines its own entry point so must either tell VS where that entry point is by setting the subsystem to console then in project properties > linker > advanced, setting the entry point to whatever SDL calls its main function (I can't remember the name sorry.) Or add a define for SDL_MAIN_HANDLED before #including SDL.h to tell SDL you want to use your own entry point.

I tried the following in main.cpp & in display.h.

#define SDL_MAIN_HANDLED

In display.h I tried above and below 

#include <SDL2/SDL.h>

and got no significant progress. 
I did however add the console application link in the subsystem where I get warnings LNK 4272 and error LNK 2019. 

From this link it says LNK 2019 is a "You didn't define the function before using it" error. Problem is that they're stated in the header file. 

4272 from Visual studio tells me that my libraries are 64 bit but my build is for 32 bit. It's odd because early scripts with reference to SDL were compiling properly. I'm not sure how to fix this. I right clicked my project, selected properties and selected 64 bit as the target platform but it declined to accept that I changed the project to 64 bit and the error persists. 

 

I also have this error LNK 1120 (10 unresolved externals)

Microsoft's website is helpful as always and tells me I should get an error code that's not appearing in my visual studio. 

I don't understand any of the errors. 
I spent quite some time trying to figure out what all these errors mean and can't figure it out. Most links seem to end abruptly or go on about something that doesn't seem to be related if not both. 

Link to comment
Share on other sites

Link to post
Share on other sites

@fizzlesticks, do you have a textbook, or guide that you recommend? 
Perhaps the place you learned to use SDL/Open GL may help me figure out how to solve my problem. 

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, fpo said:

@fizzlesticks, do you have a textbook, or guide that you recommend? 
Perhaps the place you learned to use SDL/Open GL may help me figure out how to solve my problem. 

Nope, I just used the docs when I was messing around with it.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×