Error: unrecognized command line option '-SDL2main'

I’m new to cpp and SDL, forgive me if the question is stupid. I strictly followed the instructions at http://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/codeblocks/index.php#5

and got codeblocks build messages:
||=== Build: Debug in SDL Tut (compiler: GNU GCC Compiler) ===|
||error: unrecognized command line option ‘-SDL2main’|
||error: unrecognized command line option ‘-SDL2’|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

the build log looks like this:

mingw32-g++.exe -Wall -g -IC:\mingw_dev_lib\include\SDL2 -I…\SDL2-2.0.8\i686-w64-mingw32\include -c “C:\Users\Google Drive\Development\SDL Tut\main.cpp” -o obj\Debug\main.o

mingw32-g++.exe -LC:\mingw_dev_lib\lib -L…\SDL2-2.0.8\i686-w64-mingw32\lib -o “bin\Debug\SDL Tut.exe” obj\Debug\main.o -lmingw32 -lSDL2main -lSDL2 -lmingw32 -SDL2main -SDL2

mingw32-g++.exe: error: unrecognized command line option ‘-SDL2main’

mingw32-g++.exe: error: unrecognized command line option ‘-SDL2’

Process terminated with status 1 (0 minute(s), 1 second(s))
2 error(s), 0 warning(s) (0 minute(s), 1 second(s))

Could anyone help me out? Thanks a ton!

I’m new to cpp and SDL, forgive me if the question is stupid. I strictly followed the instructions at http://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/codeblocks/index.php#5

and got codeblocks build messages:

=== Build: Debug in SDL Tut (compiler: GNU GCC Compiler) ===|
error: unrecognized command line option ‘-SDL2main’|
error: unrecognized command line option ‘-SDL2’|
=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

the build log looks like this:

mingw32-g++.exe -Wall -g -IC:\mingw_dev_lib\include\SDL2 -I…\SDL2-2.0.8\i686-w64-mingw32\include -c “C:\Users\Google Drive\Development\SDL Tut\main.cpp” -o obj\Debug\main.o

mingw32-g++.exe -LC:\mingw_dev_lib\lib -L…\SDL2-2.0.8\i686-w64-mingw32\lib -o “bin\Debug\SDL Tut.exe” obj\Debug\main.o -lmingw32 -lSDL2main -lSDL2 -lmingw32 -SDL2main -SDL2

mingw32-g++.exe: error: unrecognized command line option ‘-SDL2main’
-lSDL2main

mingw32-g++.exe: error: unrecognized command line option ‘-SDL2’
-lSDL2

It is -l (lower case L) as for library.
Those are linker-flags/arguments. Actually, for every non standard header you include you need to tell the linker, which is called from the compiler, except you say otherwise, which library to link to. -l means it is in the linker search path - with -L you can give an explicit path.

somehow you fiddled -SDL2main -SDL2 into that and -lmingw32 twice.
See if you can compile a C++ hello world with g++.

From linux shell:

gcc sdl_test.c -lSDL2 -o sdl_test

or g++ for C++. Note that filenames on linux don’t need a suffix.
And I think on MS Windows you need to link against SDL main also:

gcc sdl2test.c -lSDL2 -lSDL2main -o sdl2test.exe

If your environment supports package-config (https://www.freedesktop.org/wiki/Software/pkg-config/):

gcc sdl_test.c $(pkg-config --cflags sdl2) -o sdl_test $(pkg-config --libs sdl2)

mingw should give you a shell also.

Here is a brief introduction to gcc:

Has been a long time since I used C::B but I just started a new project on arch linux and the project wizard gave me a running SDL2 Example.


besides it looks really ugly, it works =)

–Cass