Linker error LNK2019 on including SDL.h [duplicate] - c++

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 6 years ago.
I'm trying to get my program to allow me to use C++'s input and output streams for debugging purposes but it won't work?
My code:
#include <SDL.h>
#include <iostream>
using namespace std;
int main()
{
cout << "I work!";
return 0;
}
That is all I have and it won't work. I plan to use SDL to make a small checkers game but I'd like to use <iostream> to debug.
Here's my errors:
error LNK2019: unresolved external symbol _SDL_main referenced in function _main_utf8
fatal error LNK1120: 1 unresolved externals

This is covered by FAQ:
Make sure that you are declaring main() as:
int main(int argc, char *argv[])
Since SDL_main is not special name known to C++ compiler, it mangles it by general rules. SDL have forward declaration with correct linking flags (at least extern "C") only for int SDL_main(int, char**).

Related

"Error LNK2001: unresolved external symbol _main" still exists

I know similar question is already been made but none of the answers helped me.
I get this error :
MSVCRT.lib(exe_main.obj) : error LNK2001: unresolved external symbol _main
I am using VS17. I created a Wizard Console Application and a Static Lib.
My A.cpp also looks like this
#include <iostream>
#include "A.h"
namespace img{
int main(int argc, char* argv[]{
...
return 0;
}
}
I tried changing the Properties of the Project as many suggested but everything looks fine.
Main needs to be defined in the global namespace as per conversion.

SDL unresolved external symbol

I keep getting these errors:
error LNK2005: _main already defined in main.obj
error LNK2019: unresolved external symbol _SDL_main referenced in function _main_utf8
error LNK1120: 1 unresolved externals
when building this
#include <stdio.h>
#include <SDL.h>
int main(int argc, const char* argv[]){
printf("Hi\n");
return 0;
}
I've set up the directories and the linker in Visual Studio 2013, but I can't figure out what went wrong. I'm using the 32 bit SDL runtime library. I'm also fairly new to C++.
Before your main function, define
#define SDL_MAIN_HANDLED
This stops SDL's "service" of parsing the command line for you(only on windows). Though this is a fix, this isn't good for cross platform programs. The other fix is to change main so that it looks like this:
int main(int argc, char* argv[])
You must do this because of the main macro defined in SDL_Main.h that forces you to have exactly that otherwise it will give you the error you have.

Visual Studio takes two unresolved externals with the linkers LNK2019 [duplicate]

This question already has answers here:
unresolved external symbol __imp__fprintf and __imp____iob_func, SDL2
(19 answers)
Closed 7 years ago.
My code looks like this
#include <iostream>
#include <SDL2\SDL.h>
int main(int argc, char* args[])
{
char tep;
std::cin >> tep;
return 0;
}
Visual Studio now displays the following error:
LNK1120 2 unresolved externals
LNK2019 reference to unresolved external symbol "_imp_ printf" function in "_ShowError".
LNK2019 reference to unresolved external symbol "_imp_ _iob_func" in function "_ShowError".
I have really already searched many articles about this issue, but either that what it says is true not just my problem, or the solutions are not working.
And if it helps, I have been working on the following video:https://www.youtube.com/watch?v=uzwAYyK9ZBY&feature=iv&src_vid=TC0kHYRWX1Y&annotation_id=annotation_1897517141
Thanks in advance
Try put #undef main before your entry point. I had this exact problem. Try it, and let me know how it goes.
SDL for some reason defines "#define main SDL_main"
So try something like this:
#undef main
int main(int argc, char *args[])

error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup error [duplicate]

This question already has answers here:
error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup, but this time it's NOT a Windows/Console problem!
(4 answers)
Closed 8 years ago.
I am programming SDL in C++ and I keep getting an error:
error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
What can I do to resolve this? Here is my source:
#include <SDL.h>
int main(int argc, char *argv[]){
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* Window = NULL;
Window = SDL_CreateWindow("Render Window",0,0,1000,1000, SDL_WINDOW_SHOWN || SDL_WINDOW_FULLSCREEN);
return 0;
}
My linker and compiler seem fine, I have included console in the subsystem etc. But the error only occurs when I add:
#include <SDL.h>
I think "SDL.h" internally includes "SDL_main.h", which contains a weird #define:
#define main SDL_main
which is almost certainly screwing up your own main.
Try adding #undef main after include "SDL.h", e.g.:
#include <SDL.h>
#undef main
Since you said you have already changed SubSystem to Console, that should be all you need.
See this question for more information.

error LNK2019: unresolved external symbol newbie needs tip

I am just probing some more advanced coding in C++, so imagine my frustration when I can't solve this:
1>Main.obj : error LNK2019: unresolved external symbol "int __cdecl playerAtk(void)" (? playerAtk##YAHXZ) referenced in function _main
1>C:\Users\Hezekiah Detinc\documents\visual studio 2010\Projects\Custom_1\Debug\Custom_1.exe : fatal error LNK1120: 1 unresolved externals
I had tried searching for an answer here, but the solutions I have found were too specific to be of any use for me.
If anyone can answer; What generally causes this problem? What are some solutions to fixing it?
This is my Main.cpp;
//Custom 1
//Include files that may be used. will cut out unused files in release.
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include "EnemyBaseClass.h"
#include "PlayerBaseClass.h"
using namespace std;
int main()
{
Enemy emy;
Player plr;
emy.enemyAtk();
emy.enemyDef();
emy.enemyHp();
plr.playerAtk();
plr.playerDef();
plr.playerHp();
int playerAtk();
cout << playerAtk();
cout << "You're attacked by a Monster!\n";
system(" pause ");
return 0;
}
If I need to post my headers or the other _.cpp files, let me know.
You declare and use playerAtk as a function (with no implementation, thus the undefined reference)
Change
int playerAtk();
...
cout << playerAtk();
to
int playerAtk;
...
cout << playerAtk;
(You probably want to initialize the variable)
The error is simple: You are using a function which you have declared, but you have not written any definition (Implementation). Check your source (.cpp) files.