[SDL] in linux

Started by
32 comments, last by let_bound 17 years, 1 month ago
Hi , i have a quick question to ask. I've made a simple sdl example in windows. How can i compile the same sdl test program in linux using the command line(i've installed ubuntu)? And what do i have to change in my code ? Thanks.
Advertisement
If you've been careful you should need no changes.

IIRC, to compile a single SDL source file ( provided you have the SDL-devel libraries )

g++ -o myProgram source.cpp `sdl-config --cflags --libs`

(note the `charaters are backticks)

If you get errors then post them, and the source.
It'd help to know which language and compiler/interpreter you're using.

Assuming C, it'd be something like:
gcc source_file_1.c source_file_2.c `sdl-config --cflags --libs` -o program_name

This is only useful for very simple programs though. Note that the ` ` are backticks, not single quotes.

On Ubuntu and other Debian-based distros, you'll need to have the GCC compiler and the libsdl1.2-dev packages installed.

Hope this helps.
Just because i have zero experience with linux , can you tell me how to compile & run a project that has the following files/libs included ?

IDE : DEV CPP


Main.cpp
sClasses_.cpp
sClasses_.h
sLoad.cpp
sLoad.h

Linker params:
-lmingw32
-lSDLmain
-lSDL
-lSDL_image
-lSDL_mixer
-lSDL_ttf

And what about the .dll files? where do i put them ?...

Thanks for your help so far..

edit:

This will work ? :

g++ -o TEST Main.cpp sClasses_.cpp sClasses_.h sLoad.cpp sLoad.h `sdl-config --cflags --libs -lmingw32 -lSDLmain -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf`
You don't compile .h files.

  • The SDLmain library is needed only on Windows;

  • the mingw32 library is needed only with the MinGW32 compiler, which is a port of GCC to Windows, so it's only needed on Windows as well;

  • the -l flag is a flag for g++ (it's in fact a linker option, telling it which libraries should be linked), not for the sdl-config script, so it must be outside the backticks;

  • you don't need to specify -lSDL because sdl-config --libs does it for you;

  • you don't put DLL files anywhere. DLL files are Windows things. You need the "Linux" version of SDL, not the Windows one. With Ubuntu, there's probably some kind of graphical tool to install what you need. Otherwise, you can try:
    sudo apt-get install libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev. You'll have to type your password.


Now, to build your program from the CLI, you can do:

g++ -o TEST Main.cpp sClasses_.cpp sLoad.cpp `sdl-config --cflags --libs` -lSDL_mixer -lSDL_image -lSDL_ttf


For this to work, the libSDL_image.so, libSDL_mixer.so and libSDL_ttf.so shared objects must be in a directory visible to the linker (eg /usr/lib). I'm pretty sure it's in /usr/lib on Ubuntu though, so that shouldn't cause any problem.

You'll eventually want to learn about make (or another build tool), because rebuilding everything like this is going to be extremely annoying after a moment, especially with larger projects.

Hope this helps.

EDIT: fixed typo

[Edited by - let_bound on March 6, 2007 6:40:07 AM]
To install the stuff you need for SDL, do this:

sudo apt-get install build-essential libsdl-dev
It might be worth it to look into Makefiles as well, as they can be used across multiple platforms (provided some adjustments are made) and should simplify your build process significantly.
--- ---Current Project: http://source.dev-null-productions.com/tw/"Perhaps the most fundamental problem, however, is that INTJs really want people to make sense."
We recently transitioned from hand-written makefiles for linux and hand-generated projects for Windows to using CMake. It is nice because it is cross platform, and builds the project files for whatever the native tools are. In linux, it'll generate makefiles. In Windows, we use it to generate VC++2005 projects. If I ever manage to get my hands on a Mac, it'll generate XCode projects too. My hand-written makefiles were terrible, so it's nice to have decent ones generated automatically. That might be more than you are looking to do now, but we have been happy with CMake.
Definitely read up on makefiles. It's good to know it regardless. I've got a Makefile that works both in linux and windows (Using Dev-C++ - Visual Studio is a completely different story). wikipedia entry.

This topic is closed to new replies.

Advertisement