Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi and first thanks for reading this and giving me a bit of your time !:)

So I try to do a simple hello world with SDL 2.0.3 and VisualStudio 2012.

#include <SDL.h>
#include <iostream>


int main(int argc, char **argv)
	{	
    SDL_Window* fenetre(0);
    SDL_Event evenements;
    bool terminer(false);
	

    if(SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        std::cout << "Erreur lors de l'initialisation de la SDL : " << SDL_GetError() << std::endl;
        SDL_Quit();
		
        return -1;
    }
	
	
    fenetre = SDL_CreateWindow("Test SDL 2.0", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);

    if(fenetre == 0)
    {
        std::cout << "Erreur lors de la creation de la fenetre : " << SDL_GetError() << std::endl;
        SDL_Quit();

        return -1;
    }
	
	
    while(!terminer)
    {
	SDL_WaitEvent(&evenements);
		
	if(evenements.window.event == SDL_WINDOWEVENT_CLOSE)
	    terminer = true;
    }
	
	
    SDL_DestroyWindow(fenetre);
    SDL_Quit();	
    return 0;
}


I have already installed SDL before, I've set additional lib and include folder, I also added addition dependency (SDL2.lib;SDL2main.lib). So I guess the problem is the linking because I get those errors when building

Quote:
Erreur 1 error LNK2001: symbole externe non résolu __purecall c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 2 error LNK2019: symbole externe non résolu "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) référencé dans la fonction "char * __cdecl std::_Allocate<char>(unsigned int,char *)" (??$_Allocate@D@std@@YAPADIPAD@Z) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 3 error LNK2019: symbole externe non résolu "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) référencé dans la fonction "public: virtual void * __thiscall std::_Generic_error_category::`scalar deleting destructor'(unsigned int)" (??_G_Generic_error_category@std@@UAEPAXI@Z) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 4 error LNK2019: symbole externe non résolu _atexit référencé dans la fonction "void __cdecl `dynamic initializer for 'public: static class std::_Generic_error_category std::_Error_objects<int>::_Generic_object''(void)" (??__E?_Generic_object@?$_Error_objects@H@std@@2V_Generic_error_category@2@A@@YAXXZ) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 5 error LNK2019: symbole externe non résolu _memcpy référencé dans la fonction "public: static char * __cdecl std::char_traits<char>::copy(char *,char const *,unsigned int)" (?copy@?$char_traits@D@std@@SAPADPADPBDI@Z) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 6 error LNK2019: symbole externe non résolu _strlen référencé dans la fonction "public: static unsigned int __cdecl std::char_traits<char>::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 7 error LNK2019: symbole externe non résolu __imp__memmove référencé dans la fonction "public: static char * __cdecl std::char_traits<char>::move(char *,char const *,unsigned int)" (?move@?$char_traits@D@std@@SAPADPADPBDI@Z) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 8 error LNK2019: symbole externe non résolu "__declspec(dllimport) void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (__imp_?_Debug_message@std@@YAXPB_W0I@Z) référencé dans la fonction "void __cdecl std::_Debug_pointer<char>(char const *,wchar_t const *,unsigned int)" (??$_Debug_pointer@D@std@@YAXPBDPB_WI@Z) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 9 error LNK2019: symbole externe non résolu "__declspec(dllimport) public: __thiscall std::_Container_base12::_Container_base12(void)" (__imp_??0_Container_base12@std@@QAE@XZ) référencé dans la fonction "public: __thiscall std::_String_val<struct> >::_String_val<struct> >(void)" (??0?$_String_val@U?$_Simple_types@D@std@@@std@@QAE@XZ) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 10 error LNK2019: symbole externe non résolu "__declspec(dllimport) public: __thiscall std::_Container_base12::~_Container_base12(void)" (__imp_??1_Container_base12@std@@QAE@XZ) référencé dans la fonction "public: __thiscall std::_String_val<struct> >::~_String_val<struct> >(void)" (??1?$_String_val@U?$_Simple_types@D@std@@@std@@QAE@XZ) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 11 error LNK2019: symbole externe non résolu "__declspec(dllimport) public: void __thiscall std::_Container_base12::_Orphan_all(void)" (__imp_?_Orphan_all@_Container_base12@std@@QAEXXZ) référencé dans la fonction "public: void __thiscall std::_String_alloc<0,struct std::_String_base_types<char,class> > >::_Free_proxy(void)" (?_Free_proxy@?$_String_alloc@$0A@U?$_String_base_types@DV?$allocator@D@std@@@std@@@std@@QAEXXZ) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 12 error LNK2019: symbole externe non résolu "__declspec(dllimport) void __cdecl std::_Xbad_alloc(void)" (__imp_?_Xbad_alloc@std@@YAXXZ) référencé dans la fonction "char * __cdecl std::_Allocate<char>(unsigned int,char *)" (??$_Allocate@D@std@@YAPADIPAD@Z) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 13 error LNK2019: symbole externe non résolu "__declspec(dllimport) void __cdecl std::_Xlength_error(char const *)" (__imp_?_Xlength_error@std@@YAXPBD@Z) référencé dans la fonction "public: void __thiscall std::basic_string<char,struct>,class std::allocator<char> >::_Xlen(void)const " (?_Xlen@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEXXZ) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 14 error LNK2019: symbole externe non résolu "__declspec(dllimport) void __cdecl std::_Xout_of_range(char const *)" (__imp_?_Xout_of_range@std@@YAXPBD@Z) référencé dans la fonction "public: void __thiscall std::basic_string<char,struct>,class std::allocator<char> >::_Xran(void)const " (?_Xran@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEXXZ) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 15 error LNK2019: symbole externe non résolu "__declspec(dllimport) char const * __cdecl std::_Syserror_map(int)" (__imp_?_Syserror_map@std@@YAPBDH@Z) référencé dans la fonction "public: virtual class std::error_condition __thiscall std::_System_error_category::default_error_condition(int)const " (?default_error_condition@_System_error_category@std@@UBE?AVerror_condition@2@H@Z) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 16 error LNK2019: symbole externe non résolu "__declspec(dllimport) char const * __cdecl std::_Winerror_map(int)" (__imp_?_Winerror_map@std@@YAPBDH@Z) référencé dans la fonction "public: virtual class std::basic_string<char,struct>,class std::allocator<char> > __thiscall std::_System_error_category::message(int)const " (?message@_System_error_category@std@@UBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@H@Z) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 17 error LNK2019: symbole externe non résolu @_RTC_CheckStackVars@8 référencé dans la fonction "public: void __thiscall std::_String_alloc<0,struct std::_String_base_types<char,class> > >::_Alloc_proxy(void)" (?_Alloc_proxy@?$_String_alloc@$0A@U?$_String_base_types@DV?$allocator@D@std@@@std@@@std@@QAEXXZ) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 18 error LNK2019: symbole externe non résolu @__security_check_cookie@4 référencé dans la fonction __unwindfunclet$??$construct@PADAAPAD@?$allocator@D@std@@QAEXPAPADAAPAD@Z$0 c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 19 error LNK2019: symbole externe non résolu __CxxThrowException@8 référencé dans la fonction __catch$?_Copy@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXII@Z$1 c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 20 error LNK2019: symbole externe non résolu __RTC_CheckEsp référencé dans la fonction "char * __cdecl std::_Allocate<char>(unsigned int,char *)" (??$_Allocate@D@std@@YAPADIPAD@Z) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 21 error LNK2001: symbole externe non résolu __RTC_InitBase c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 22 error LNK2001: symbole externe non résolu __RTC_Shutdown c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 23 error LNK2019: symbole externe non résolu ___CxxFrameHandler3 référencé dans la fonction __unwindfunclet$??$construct@PADAAPAD@?$allocator@D@std@@QAEXPAPADAAPAD@Z$0 c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 24 error LNK2001: symbole externe non résolu "const type_info::`vftable'" (??_7type_info@@6B@) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 25 error LNK2019: symbole externe non résolu ___security_cookie référencé dans la fonction "public: void __thiscall std::allocator<char>::construct<char>(char * *,char * &)" (??$construct@PADAAPAD@?$allocator@D@std@@QAEXPAPADAAPAD@Z) c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 26 error LNK2001: symbole externe non résolu _mainCRTStartup c:\Users\holder\documents\visual studio 2012\Projects\SDL1\LINK SDL1
Erreur 27 error LNK1120: 26 externes non résolus c:\users\holder\documents\visual studio 2012\Projects\SDL1\Debug\SDL1.exe SDL1



Quote:
I can run this simple sdl code

C#
// Example program:
// Using SDL2 to create an application window
 
#include "SDL.h"
#include <stdio.h>
 
int main(int argc, char* argv[]) {
 
SDL_Window *window; // Declare a pointer
 
SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2
 
// Create an application window with the following settings:
window = SDL_CreateWindow(
"An SDL2 window", // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position
640, // width, in pixels
480, // height, in pixels
SDL_WINDOW_OPENGL // flags - see below
);
 
// Check that the window was successfully made
if (window == NULL) {
// In the event that the window could not be made...
printf("Could not create window: %s\n", SDL_GetError());
return 1;
}
 
// The window is open: enter program loop (see SDL_PollEvent)
 
SDL_Delay(3000); // Pause execution for 3000 milliseconds, for example
 
// Close and destroy the window
SDL_DestroyWindow(window);
 
// Clean up
SDL_Quit();
return 0;
}



I only got a warning
Quote:
Avertissement 1 warning LNK4098: conflit entre la bibliothèque par défaut 'msvcrt.lib' et les autres bibliothèques ; utilisez /NODEFAULTLIB:library c:\Users\holder\documents\visual studio 2012\Projects\SDL1\MSVCRTD.lib(cinitexe.obj) SDL1


I've tried to use the /NODEFAULTLIB but if I do that I got the same errors as before.

Here is my building command line

Quote:
/OUT:"c:\users\holder\documents\visual studio 2012\Projects\SDL1\Debug\SDL1.exe" /MANIFEST /NXCOMPAT /PDB:"c:\users\holder\documents\visual studio 2012\Projects\SDL1\Debug\SDL1.pdb" /DYNAMICBASE "SDL2.lib" "SDL2main.lib" "glew32.lib" /DEBUG /MACHINE:X86 /INCREMENTAL /PGD:"c:\users\holder\documents\visual studio 2012\Projects\SDL1\Debug\SDL1.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\SDL1.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /VERBOSE /LIBPATH:"C:\Users\holder\Work\DustPlanet\glew-1.11.0\lib\Release\Win32" /LIBPATH:"C:\Users\holder\Work\DustPlanet\SDL2-2.0.3\lib\x86" /TLBID:1



Moreover I need to use glew, I got the same kind of erros when I try adding gluw.



Some pictures of mt configuration:

http://i.imgur.com/JqbROVN.png

http://i.imgur.com/LkQvzno.png

http://i.imgur.com/DYe4vJ2.png

http://i.imgur.com/Rykqq5x.png
Posted
Updated 4-Nov-14 16:41pm
v5

1 solution

Francais ? pas un problem monsieur !

(but I'd better stick to English in case I get accused of murdering such a lovely language and find myself heading to 'madame le guillotine')

1st up -- does SDL come with any examples/pre-built projects ? if so, its always been best in my experience to build one of those as a starter, just to make sure all the pieces are there

if not, we're going to have to pull apart your settings bit by bit, although it sounds like you have the correct idea of what you need to do :-)

[edit] - did you download the source version and have a look at the 'VisualC.html' doc [/edit]
 
Share this answer
 
v2
Comments
Lambert Cayrel 4-Nov-14 22:29pm    
I can run this simple sdl code

<pre lang="cs">// Example program:
// Using SDL2 to create an application window

#include "SDL.h"
#include <stdio.h>

int main(int argc, char* argv[]) {

SDL_Window *window; // Declare a pointer

SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2

// Create an application window with the following settings:
window = SDL_CreateWindow(
"An SDL2 window", // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position
640, // width, in pixels
480, // height, in pixels
SDL_WINDOW_OPENGL // flags - see below
);

// Check that the window was successfully made
if (window == NULL) {
// In the event that the window could not be made...
printf("Could not create window: %s\n", SDL_GetError());
return 1;
}

// The window is open: enter program loop (see SDL_PollEvent)

SDL_Delay(3000); // Pause execution for 3000 milliseconds, for example

// Close and destroy the window
SDL_DestroyWindow(window);

// Clean up
SDL_Quit();
return 0;
}</pre>


I only got a warning <blockquote class="quote"><div class="op">Quote:</div>Avertissement 1 warning LNK4098: conflit entre la bibliothèque par défaut 'msvcrt.lib' et les autres bibliothèques ; utilisez /NODEFAULTLIB:library c:\Users\holder\documents\visual studio 2012\Projects\SDL1\MSVCRTD.lib(cinitexe.obj) SDL1
</blockquote>

I've tried to use the /NODEFAULTLIB but if I do that I got the same errors as before.

Here is my building command line

<blockquote class="quote"><div class="op">Quote:</div>/OUT:"c:\users\holder\documents\visual studio 2012\Projects\SDL1\Debug\SDL1.exe" /MANIFEST /NXCOMPAT /PDB:"c:\users\holder\documents\visual studio 2012\Projects\SDL1\Debug\SDL1.pdb" /DYNAMICBASE "SDL2.lib" "SDL2main.lib" "glew32.lib" /DEBUG /MACHINE:X86 /INCREMENTAL /PGD:"c:\users\holder\documents\visual studio 2012\Projects\SDL1\Debug\SDL1.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\SDL1.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /VERBOSE /LIBPATH:"C:\Users\holder\Work\DustPlanet\glew-1.11.0\lib\Release\Win32" /LIBPATH:"C:\Users\holder\Work\DustPlanet\SDL2-2.0.3\lib\x86" /TLBID:1 </blockquote>


Moreover I need to use glew, I got the same kind of erros when I try adding gluw.
Lambert Cayrel 4-Nov-14 22:35pm    
Some pictures of mt configuration:

http://i.imgur.com/JqbROVN.png

http://i.imgur.com/LkQvzno.png

http://i.imgur.com/DYe4vJ2.png

http://i.imgur.com/Rykqq5x.png
Garth J Lancaster 4-Nov-14 22:55pm    
ok, first things .. in your source code, I'd move the
include for SDL.h
below all other includes (iostream) in this case

I also note on this http://i.imgur.com/Rykqq5x.png that you use ';' to separate the libraries - you'd have to refresh my memory if it was ';' or ' ' (space) - Im still looking to see if I can spot your issue
Lambert Cayrel 4-Nov-14 23:10pm    
Is it better to include like this "SDL.h" or with < ? Putting the SDL define worked even if still got this warning

Avertissement 1 warning LNK4098: conflit entre la bibliothÞque par dÚfaut 'msvcrt.lib' et les autres bibliothÞquesá; utilisez /NODEFAULTLIB:library c:\Users\holder\documents\visual studio 2012\Projects\SDL1\MSVCRTD.lib(cinitexe.obj) SDL1

And when I try to use glew I got the same errors as before

Avertissement 1 warning LNK4098: conflit entre la bibliothÞque par dÚfaut 'msvcrt.lib' et les autres bibliothÞquesá; utilisez /NODEFAULTLIB:library c:\Users\holder\documents\visual studio 2012\Projects\SDL1\MSVCRTD.lib(cinitexe.obj) SDL1
Erreur 2 error LNK2019: symbole externe non rÚsolu __imp__glClear@4 rÚfÚrencÚ dans la fonction _SDL_main c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 3 error LNK2019: symbole externe non rÚsolu __imp__glDrawArrays@12 rÚfÚrencÚ dans la fonction _SDL_main c:\Users\holder\documents\visual studio 2012\Projects\SDL1\main.obj SDL1
Erreur 4 error LNK1120: 2 externes non rÚsolus c:\users\holder\documents\visual studio 2012\Projects\SDL1\Debug\SDL1.exe SDL1


Thanks you for your time again :o
Garth J Lancaster 4-Nov-14 23:34pm    
btw '<' and '>' around libraries I was taught was only for system libraries

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900