Page 1 of 1

[Solved] SDL library technical error

Posted: Mon Mar 19, 2012 11:52 am
by zircle

Text is redirected to a textfile in the same directory as the executable.


The following code compiles with 0 errors. However, when running the program, as long as "#include "SDL/SDL.h" is included, the program does not output.

Code: Select all

#include <iostream>
#include "SDL/SDL.h"
int main( int argc, char* args[] )
{
std::cout << "fasdddasdfdusaasdfcker";
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
    
//Quit SDL
SDL_Quit();
return 0;
}
I've extracted the SDL folder into my C:\ directory and I think I have properly linked them up to CodeLite.

Compiler:
compiler.png
Linker:
linker.png
Here is the output that I get:
output.png

Re: SDL library technical error

Posted: Mon Mar 19, 2012 2:21 pm
by eranif
I can think of stdout redirection by SDL..

have you tried writing to stderr? how about adding std::endl at the end of the std::cout ?

Code: Select all

std::cerr << "Hello" << std::endl;
If you remove the SDL does this still happens? (remove the include + libraries)

Eran

Re: SDL library technical error

Posted: Mon Mar 19, 2012 7:30 pm
by zircle
Fast response.. <3

The line of code you gave me doesn't work.

If I remove the "#include "SDL/SDL.h" and comment out all the SDL functions, it works fine.

If I remove the linked libraries and includes (but "SDL/SDL.h" is still #include(d)):

Code: Select all

C:\Windows\system32\cmd.exe /c ""mingw32-make.exe"  -j 8 -f "Workspace_wsp.mk""
----------Building project:[ SDL_Workshop - Debug ]----------
mingw32-make.exe[1]: Entering directory `C:/Users/Public/Documents/Workspace/SDL_Workshop'
g++ -o ./Debug/SDL_Workshop @"C:\Users\Public\Documents\Workspace\SDL_Workshop\SDL_Workshop.txt" -L.   
./Debug/main.o: In function `SDL_main':
C:/Users/Public/Documents/Workspace/SDL_Workshop/main.cpp:8: undefined reference to `SDL_Init'
C:/Users/Public/Documents/Workspace/SDL_Workshop/main.cpp:11: undefined reference to `SDL_Quit'
c:/mingw-4.6.1/bin/../lib/gcc/mingw32/4.6.1/../../../libmingw32.a(main.o): In function `main':
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/SDL_Workshop] Error 1
mingw32-make.exe: *** [All] Error 2
mingw32-make.exe[1]: Leaving directory `C:/Users/Public/Documents/Workspace/SDL_Workshop'
----------Build Ended----------
3 errors, 0 warnings
edit::
hrm.. I moved the Options field to the Libraries field:

Code: Select all

mingw32;SDL;SDLmain
and I get this:

Code: Select all

----------Build Started--------
C:\Windows\system32\cmd.exe /c ""mingw32-make.exe"  -j 8 -f "Workspace_wsp.mk""
----------Building project:[ SDL_Workshop - Debug ]----------
mingw32-make.exe[1]: Entering directory `C:/Users/Public/Documents/Workspace/SDL_Workshop'
g++ -o ./Debug/SDL_Workshop @"C:\Users\Public\Documents\Workspace\SDL_Workshop\SDL_Workshop.txt" -L. -LC:/SDL-1.2.15/lib  -lmingw32 -lSDL -lSDLmain  
C:/SDL-1.2.15/lib/libSDLmain.a(SDL_win32_main.o): In function `redirect_output':
/Users/slouken/release/SDL/SDL-1.2.15/./src/main/win32/SDL_win32_main.c:219: undefined reference to `SDL_strlcpy'
/Users/slouken/release/SDL/SDL-1.2.15/./src/main/win32/SDL_win32_main.c:220: undefined reference to `SDL_strlcat'
/Users/slouken/release/SDL/SDL-1.2.15/./src/main/win32/SDL_win32_main.c:243: undefined reference to `SDL_strlcpy'
/Users/slouken/release/SDL/SDL-1.2.15/./src/main/win32/SDL_win32_main.c:244: undefined reference to `SDL_strlcat'
C:/SDL-1.2.15/lib/libSDLmain.a(SDL_win32_main.o): In function `console_main':
/Users/slouken/release/SDL/SDL-1.2.15/./src/main/win32/SDL_win32_main.c:296: undefined reference to `SDL_strlcpy'
/Users/slouken/release/SDL/SDL-1.2.15/./src/main/win32/SDL_win32_main.c:301: undefined reference to `SDL_GetError'
/Users/slouken/release/SDL/SDL-1.2.15/./src/main/win32/SDL_win32_main.c:312: undefined reference to `SDL_SetModuleHandle'
C:/SDL-1.2.15/lib/libSDLmain.a(SDL_win32_main.o): In function `WinMain@16':
/Users/slouken/release/SDL/SDL-1.2.15/./src/main/win32/SDL_win32_main.c:354: undefined reference to `SDL_getenv'
/Users/slouken/release/SDL/SDL-1.2.15/./src/main/win32/SDL_win32_main.c:386: undefined reference to `SDL_strlcpy'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/SDL_Workshop] Error 1
mingw32-make.exe: *** [All] Error 2
mingw32-make.exe[1]: Leaving directory `C:/Users/Public/Documents/Workspace/SDL_Workshop'
----------Build Ended----------
9 errors, 0 warnings
slouken is not my username

edit2:
I'm on windows 7 64bit

Re: SDL library technical error

Posted: Mon Mar 19, 2012 9:30 pm
by eranif
zircle wrote:C:/SDL-1.2.15/lib/libSDLmain.a(SDL_win32_main.o): In function `redirect_output':
I am not SDL expert, but this line is the source of your problem: SDL redirects the stdout output to somewhere... (try searching google for SDL redirection, for example: http://stackoverflow.com/questions/5877 ... -c-windows)

For the rest:
Its not really related to codelite... its more of SDL issues

Eran

Re: SDL library technical error

Posted: Mon Mar 19, 2012 10:57 pm
by zircle
Ah, you are right.

I was fiddling around with it and it turns out that the order of the linker needs to be in this order:

Code: Select all

lmingw32;lSDLmain;lSDL
and all console output is redirected to a textfile(".txt") in the executable folder. As long as SDL works, I guess it is alright.

Thanks for your help.