having problems in installing SDL 2

Pages: 12
i download SDL 2 and tried to install it by watching setup tutorials
i done everything as they said but still nothing work (i tried 10+- different tutorials )
everytime i run the code i got 3 errors:
"undefined refrences to SDL_Init"
"undefined refrences to SDL_Quit"
"undefined refrences to SDL_WinMain@16"
i tried every single one of the 3 options - when i download i had 3 folders:
(1)x86_64-w64-mingw32, (2)x86_64-w64-mingw32, (3) [include, lib, test].
im using Codeblocks
and i wrote on the linker options -lmingw32 -lSDL2main -lSDL2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include "SDL.h"

using namespace std;

int main() {

	if(SDL_Init(SDL_INIT_VIDEO) < 0 ) {
		return 1;
	}
	cout << "hi" << endl;
	SDL_Quit();
	return 0;
}
sdl libraries aren't getting linked in somehow. Try putting the sdl ones first before mingw32 and see what happens.
still not working... :/
i read this : https://wiki.libsdl.org/FAQWindows
maybe my problem related to this somehow?
some with this command maybe? sdl-config --libs
or gcc -o test test.c sdl-config --cflags --libs
i just dont know how to configure this to my compiler
Last edited on
Alternative

Code::Blocks comes with support for reading .DevPak files of late. This allows for an even more comfortable setup. DevPaks (1.2.8) for SDL, SDL-mixer, and SDL-ttf can be found at http://www.devpaks.org/category.php?category=SDL.
Important: Please do note that the packages at devpaks.org are not original packages created by the SDL team. Be aware that devpaks.org theoretically allows anyone to upload anything under the name SDL. Although I know of no case of malware being distributed over this channel, this is a potential risk you have to be aware of.

from http://wiki.codeblocks.org/index.php?title=Using_SDL_with_Code::Blocks

try to install it with a devpack
Last edited on
you mean that this is a risk only if i distribute some of my programms right?
and this is the only way? anyone who have CodeBlocks have that problem?


i tried it now didnt understand what is it done
i copy the files locations and add it to the linker and compiler and still i got errors
im a beginner in all this stuff if you can please give me more extensive explanation
Last edited on
This is a sample code i made to display an image. it does require you to have SDL2 and SDL2-Image setup.

Configuration Properies -> VC++ Directories ->

Include Directories = $(SolutionDir)\SDL\SDL2-Image\2.0.0\include; $(SolutionDir)\SDL\SDL2\2.0.1\include
Library Directories = $(SolutionDir)\SDL\SDL2-Image\2.0.0\lib\x86; $(SolutionDir)\SDL\SDL2\2.0.1\lib\x86

note your settings may very depending on where you have placed SDL. als dont forget to copy the dlls from the lib folders to you debug folder.

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
#pragma comment (lib, "SDL2.lib")
#pragma comment (lib, "SDL2main.lib")
#pragma comment (lib, "SDL2_image.lib")
#include <SDL.h>
#include <SDL_image.h>
#include <assert.h>

int main(int, char**)
{
	SDL_Init(SDL_INIT_EVERYTHING);
	SDL_Window* window = SDL_CreateWindow("My Game Window",
		SDL_WINDOWPOS_UNDEFINED,
		SDL_WINDOWPOS_UNDEFINED,
		640, 480,
		0); //SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL);

	SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);

	SDL_Surface* image = IMG_Load("hello.png");
	assert(image);

	SDL_Texture* sdlTexture = SDL_CreateTextureFromSurface(renderer, image);
	SDL_FreeSurface(image);

	SDL_RenderCopy(renderer, sdlTexture, 0, 0);

	SDL_RenderPresent(renderer);


	while (true)
	{
		SDL_Event event;
		if (SDL_PollEvent(&event))
		{
			if (event.type == SDL_QUIT)
			{
				break;
			}
		}
	}

	SDL_Quit();
	return 0;
}


oh and you will need a "hello.png" Image not PNG part bmp images seem to fail on my pc.
Last edited on
Somebody clearly didnt read this is on code::blocks (mingw), not on VS.
Somehow, mingw "dislikes" sdl.
Reordering your linker flags is all I can think of.
emmm i didnt find the VC++ DIRECTIORES in CODEBLOCKS
and i just want to install successfully the SDL i dont know nothing about all this images types and stuff....

and i tried to reordering as the first guy say, that didnt work
Last edited on
Tried putting -mwindows with the linker flags?
Edit: "Other Linker Options"
Also your libraries should go under "Linker Libraries", one each line, without -l prefix.

Sorry for the multiple edits, I'm typing from my phone.
Last edited on
ah sorry about that, i did not get the Codeblocks part. but i guess the code should still work and you will still need to do your linking so the principal stays the same as for where to set the settings i have no idea sorry about that.

my explanation was for VisualStudio.
The problem is, his code is not the issue but his project settings - which means most of your post will be useless in this thread, and you just found yourself writing, uh, "less useful" code.
@op: Can you check the linker's log (it should come together with the compiler's log)?
Can you find "missing -lSDL2main" or similar?
If so, you need to set up the linker's search folder, adding your sdl2 /lib folder.
Last edited on
yep i tried -mwindows + adding every single .lib file, still doesnt work.
this is the pictures if that will help you understand more about my situation
http://prntscr.com/581zbt
http://prntscr.com/581zn4
** this is more like my old pictures
i add the -mwindows and tried reordering the l flags and i add the .lib to the "Link libraries:"

by the way thank you very much to all of you guys for helping me solving this problem i tried in other forums they just gave up XD
Last edited on
Try using the x86 lib folder. Usually, codeblocks comes with a x86 MinGW. Unless you are sure you have MinGW-w64 installed and configured for codeblocks.

Note: for x64, manually compiling sdl2 may be better, but requires you to find all dependencies, so i'll opt-out as of now since I can't help with that from mobile.

Np, all problems have a solution... Maybe it will just take a different amount of time, but there's solutions
Last edited on
tried 86x its crushs codeblock and destory my program
i noticed that my CodeBlocks install in the x86 program files folder
maybe if i reinstall it in the normal program files folder (x64) it will work?
No, it shouldn't be related.
I'll be probably needing to be on pc to check it out.
If you really want to do something til tomorrow, try installing codeblocks again, but make sure everything is either x86 or x64, without mixing them. This may not be the case, tho.
-- Are the files in x64 folder named lib_.a or _.lib ?

Edit: I gave it a slight eye. i686 folder is for x86, x86_64 is for x64. The other include/lib/bin are for VS (there should be some support from mingw)
Last edited on
Ok iwill check that when i get home
Any luck with this yet?
still nothing i tried to reinstall codeblocks on x64 and refer the compiler to the right libs (x64)
no results :/
and my files in x64 folder named lib_.a
uhm maybe you should set -everything- up for x86,...
done it and now it says:
fatal error: winapifamily.h : no such file or directory
by the way, the SDL folder location matter?
because its on the desktop
Last edited on
Pages: 12