LNK1561 entry point must be defined - SDL - c++

I got a LNK1561 entry point must be defined error i tried somethings my self as stsyem settings to console and it still doesn't work. Here is my code for every class the SDl.h is from the SDL.h donwload page.
main.cpp:
#include <iostream>
#include "MainGame.h"
int main(int argc, char** argv) {
std::cout << "Enter any ket to quit...";
int a;
std::cin >> a;
return 0;
}
MainGame.cpp:
#include "MainGame.h"
MainGame::MainGame()
{
_window = nullptr;
_screenHeight = 1028;
_screenWidth = 768;
}
MainGame::~MainGame()
{
}
void MainGame::run() {
InitSystems();
}
void MainGame::InitSystems() {
SDL_Init(SDL_INIT_EVERYTHING);
_window = SDL_CreateWindow("title", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, 1028, 768, SDL_WINDOW_OPENGL);
}
MainGame.h:
#pragma once
#include <SDL/SDL.h>
class MainGame
{
public:
MainGame();
~MainGame();
void run();
void InitSystems();
private:
SDL_Window* _window;
int _screenWidth;
int _screenHeight;
};
Allt his code is to open an Windowed frame on your computer en open an console with the text Press Any ket to quit... If i remove the SDL.h include and the SDL code it all works if i put the include back and not the SDL code it gives the error again.

Have you tried using MainGame in your main function? Chances that the compiler assumes that it is never used and you do not get the #include <SDL/SDL.h> directive to work. Also, consider changing #include <SDL/SDL.h> to #include "SDL/SDL.h".
Also you might consider using SDL_SetMainReady for the cases that you are not using SDL_Main as the entry point.

Related

SFML 2.0 - Window closes immediately after showing up

Window immediately closes after showing up, even though it should wait for close event.
main.h:
#include <SFML/Graphics.hpp>
#include <iostream>
#include "window.h"
int main()
{
window::window mainwindow;
mainwindow.createwindow(800, 600);
while(mainwindow.window.pollEvent(mainwindow.events)){
if (mainwindow.events.type == sf::Event::Closed){
mainwindow.window.close();
}
}
return 0;
}
window.h:
#include <SFML/Graphics.hpp>
#include <iostream>
namespace window{
class window{
public:
sf::Window window;
sf::Event events;
void createwindow(int resx, int resy){
window.create(sf::VideoMode(resx, resy), "MainWindow", sf::Style::Default);
}
};
}
The code is based on this SFML tutorial : https://www.sfml-dev.org/tutorials/2.5/window-window.php
I am using SMFL 2-2.5.1-23.83 with IDE being code::blocks 20.03.
Thanks for all help

"Cannot open include file: 'vulkan/vulkan.h': No such file or directory" when static library is build as part of a solution in VS 2019

I'm currently experimenting with the vulkan API and have trouble building my solution with VS 2019.
The setup is as follows:
I have a multi-project solution with 2 projects: A static library called *Engine* and an application called *Game*.
External libs: vulkan, GLFW and GLM.
Dependencies are configured almost the same as described in [Vulkan Tutorial][1] with slight adjustments for the static lib, exact setup can be found at the end of this post on screenshots.
My problem is this:
When I build the Engine by itself, everything is fine and no errors occur.
If I build the whole solution and only #include "Engine.h" or "util.h" in "Game.cpp" (source file with main method in Game) then it works as well and if I execute it a window opens and the debug output is correct as well.
But if I #include "Configuration.h" in "Game.cpp" the error as stated in the title occurs.
The only difference I notice between the files is that "Engine.h" and "util.h" do not include any vulkan code but rather their source file counterparts "Engine.cpp" and "util.cpp" do, while "Configuration.h" contains #include "vulkan/vulkan.h".
Does anyone have any idea what might be the problem and how to fix it?
Code
Engine.h
#pragma once
namespace re
{
class REngine
{
public:
void init();
};
}
Engine.cpp
#include "Engine.h"
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
//std
#include <iostream>
namespace re {
void REngine::init()
{
#ifdef _DEBUG
std::cout << "Realms Engine begin initializing." << std::endl;
#endif // _DEBUG
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow* window = glfwCreateWindow(800, 600, "Vulkan window", nullptr, nullptr);
uint32_t extensionCount = 0;
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
std::cout << extensionCount << " extensions supported\n";
glm::mat4 matrix;
glm::vec4 vec;
auto test = matrix * vec;
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
}
}
Configuration.h
#pragma once
#include "vulkan/vulkan.h"
namespace re {
class RConfiguration
{
private:
VkApplicationInfo m_appInfo;
const int m_height;
const int m_width;
public:
RConfiguration(
const char* name,
int height, int width,
int major, int minor, int patch
);
const int get_width() { return m_width; }
const int get_height() { return m_height; }
VkApplicationInfo get_app_info() { return m_appInfo; }
};
}
Configuration.cpp
#include "Configuration.h"
namespace re {
RConfiguration::RConfiguration(const char* name, int height, int width, int major, int minor, int patch): m_height(height), m_width(width)
{
m_appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
m_appInfo.pApplicationName = name;
m_appInfo.applicationVersion = VK_MAKE_VERSION(major, minor, patch);
m_appInfo.pEngineName = "Realms Engine";
m_appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
m_appInfo.apiVersion = VK_API_VERSION_1_2;
}
}
Game.cpp
#include <iostream>
#include "Engine.h"
#include "util.h"
#include "Configuration.h"
int main()
{
std::cout << "Hello World!\n";
re::REngine engine;
auto version = re::util::make_version(1, 2, 1);
std::cout << version << std::endl;
engine.init();
}
re::RConfiguration make_config() {
return re::RConfiguration(
"Realms in the Sky",
600,
800,
1, 0, 0
);
}
Project Setup
Engine
Game

SDL Window won't pop up

My window won't pop up.
Console appears, and without opening window just says that "Application ended"
Here is my code:
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_image.h>
#include <windows.h>
using namespace std;
SDL_Window * okno;
SDL_Surface * ekran;
SDL_Event zdarzenie;
int frame = 0;
int main(int argc, char*args[])
{
SDL_Init(SDL_INIT_EVERYTHING);
return 0;
okno = SDL_CreateWindow("SDL_TEST", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, NULL);
ekran = SDL_GetWindowSurface(okno);
}
return 0; is your bug. After the return the program ends because main() ends. No lines in main are executed after the return. You certainly did not want to end before you called SDL_CreateWindow.
Can a function continue after a return statement?
Change the code to
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_image.h>
#include <windows.h>
using namespace std;
SDL_Window * okno;
SDL_Surface * ekran;
SDL_Event zdarzenie;
int frame = 0;
int main(int argc, char*args[])
{
SDL_Init(SDL_INIT_EVERYTHING);
okno = SDL_CreateWindow("SDL_TEST", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, NULL);
ekran = SDL_GetWindowSurface(okno);
}
In c++ return 0; can be omitted from main.
Can I omit return from main in C?
Also I would expect this code to issue a warning (about unreachable code) on many compilers. If it did not warn you may need to turn up the warning level of your compiler. If it did warn you need to pay more attention to the warnings..
You may also want to remove the global variables and instead make your variables local to main. Global variables are usually considered a bad practice.
Are global variables bad?
Also SDL_Init() can fail. You may want to check its return value and quit on failure logging the error.
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
SDL_Log("Unable to initialize SDL: %s", SDL_GetError());
return 1;
}
https://wiki.libsdl.org/SDL_Init

Displaying window with sfml

I looked for some tutorials for game development, I found one where I'm supposed to create a pong clone, but I can't even create the window, I get the following:
"Unhandled exception at 0xEEFFEE01 in Pang.exe: 0xC0000005: Access violation reading location 0xEEFFEE01."
I'm using SFML 1.6 and Visual Studio 2013.
Here is my code.
Game.cpp
#include "stdafx.h"
#include "Game.h"
void Game::Start(void)
{
if (_gameState != Uninitialized)
return;
_mainWindow.Create(sf::VideoMode(1024, 768, 32), "Pang!");
_gameState = Game::Playing;
while (!IsExiting())
{
GameLoop();
}
_mainWindow.Close();
}
bool Game::IsExiting()
{
if (_gameState == Game::Exiting)
return true;
else
return false;
}
void Game::GameLoop()
{
sf::Event currentEvent;
while (_mainWindow.GetEvent(currentEvent))
{
switch (_gameState)
{
case Game::Playing:
{
_mainWindow.Clear(sf::Color(255, 0, 0));
_mainWindow.Display();
if (currentEvent.Type == sf::Event::Closed)
{
_gameState = Game::Exiting;
}
break;
}
}
}
}
Game::GameState Game::_gameState = Uninitialized;
sf::RenderWindow Game::_mainWindow;
Game.h
#pragma once
#include "SFML/Window.hpp"
#include "SFML/Graphics.hpp"
class Game
{
public:
static void Start();
private:
static bool IsExiting();
static void GameLoop();
enum GameState {
Uninitialized, ShowingSplash, Paused,
ShowingMenu, Playing, Exiting
};
static GameState _gameState;
static sf::RenderWindow _mainWindow;
};
Pang.cpp
#include "stdafx.h"
#include "Game.h"
int _tmain(int argc, _TCHAR* argv[])
{
Game::Start();
return 0;
}
I know there's some code that has nothing to do with my problem, the error occurs when it reaches this line in Game.cpp
_mainWindow.Display();
I'm new on this so any help, any good tutorials or starting point to start learning will be good.
Some general SFML advice: Update to SFML 2.0, especially if you are using VS2013. Here are the official SFML tutorials http://www.sfml-dev.org/tutorials/2.0/
It looks like you just copied your code from here http://en.sfml-dev.org/forums/index.php?topic=10855.0 if this is true you should have realized that the code did not work, if not then the person who copied the code and used it in their tutorial should have noticed, and the fact they didn't is worrying about the state of the rest of their tutorials
Okay so the issue is you can't have a static RenderWindow, and with that your entire game class should not be static, it just isn't good programming practice. What you need to do is remove the static identifier from every declaration in your Game.h header file. For instance:
This
static void Start();
Needs to look like this
void Start();
Next, your Pang.cpp should look like this
//#include "stdafx.h" you don't need this precompiled header
#include "Game.h"
int main(int argc, char* argv[])
{
Game myGame;
myGame.Start();
return 0;
}

Window refuses to render

I recently got started trying to use SFML. For some reason my simple program will not render the window. I've tried throwing everything into main to see if there was an error in my code that had to do with multiple files etc. but to no avail.
I'll launch my program and nothing will appear.
What's the problem?
//main.h
#ifndef MAIN_H
#define MAIN_H
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include <fstream>
using namespace std;
using namespace sf;
class game
{
public:
void startLoop(int SCREEN_W, int SCREEN_H, string SCREEN_NAME);
void log(const string logging);
game()
{
QUIT = false;
pendingFile.open("Log.txt", ios::out);
pendingFile << "---Brain Bread Log---";
}
~game()
{
pendingFile.close();
}
private:
bool QUIT;
ofstream pendingFile;
};
#endif
//main.cpp
#include "main.h"
void game::log(const string logging)
{
pendingFile << logging;
}
void game::startLoop(int SCREEN_W, int SCREEN_H, string SCREEN_NAME)
{
Window Game(VideoMode(SCREEN_W, SCREEN_H, 32), SCREEN_NAME);
while(QUIT == false)
{
Game.Display();
}
}
int main(int argc, char* argv[])
{
game gameObj;
gameObj.startLoop(800, 600, "Brain Bread");
return 0;
}
I tried your code and it behaves exactly as I expect it to - that is to say that an iconless window with a black body pops up and it doesn't respond to events. Is that what you're getting? If not, you might need to rebuild SFML.
You might want to try introducing event-handling so that your startLoop looks more like this:
void game::startLoop(int SCREEN_W, int SCREEN_H, string SCREEN_NAME)
{
// Init stuff
while (Game.IsOpened())
{
sf::Event newEvent;
while (Game.GetEvent(newEvent))
{
// Process event
}
// Do graphics stuff
Game.Display();
}
}