0
votes

I'm trying to link SDL2 on Raspbian Stretch, which is debian-based.

I followed the instructions:

Debian-based systems (including Ubuntu) can simply do "sudo apt-get install libsdl2-2.0" to get the library installed system-wide, and all sorts of other useful dependencies, too.

But I have no idea where in the world that installed it and a find . -name **sdl* didn't really help... meanwhile my build command in gnat still tells me it's not finding anything:

gnatmake -g main.adb -Isource -I../source/win -I../source -I../SDL2 -gnatwk -gnatwr -gnatwu -D objectFiles -largs -lSDL2 -lSDL2_Mixer -lSDL2_ttf obj1.o obj2.o
(...)
/usr/bin/ld: cannot find -lSDL2
/usr/bin/ld: cannot find -lSDL2_Mixer
/usr/bin/ld: cannot find -lSDL2_ttf
(...)

So I tried building myself according to the instructions below that:

If you're compiling SDL yourself, here's what we refer to as "the Unix way" of building:

  • Get a copy of the source code, either from Mercurial or an official tarball or whatever.
  • Make a separate build directory (SDL will refuse to build in the base of the source tree).
  • Run the configure script to set things up.
  • Run "make" to compile SDL.
  • Run "make install" to install your new SDL build on the system.

This looks something like this:

hg clone https://hg.libsdl.org/SDL SDL
cd SDL
mkdir build
cd build
../configure
make
sudo make install

Everything did what it was supposed to do (or at least nothing said it DIDN'T do what it was supposed to do) but now I still don't know how to link it. I tried copying the libsdl2.so file to the working directory and changing -lSDL2 to -llibsdl2 but no luck. Obviously I need to do the same procedure with the other libraries but I was hoping I could worry about one at a time.

There are further instructions but they seem to apply specifically to C:

Once you have the library installed, you can use the sdl2-config program to help you compile your own code:

gcc -o myprogram myprogram.c `sdl2-config --cflags --libs`

And I don't know how to do something similar for Ada.

Problem is, I just have no experience linking in Linux and all the stuff I can find on the internet is so general I can't apply it to my case.

As for why in the world I would want to do this, building this for Raspberry Pi wasn't something I intended from the start of the project, but it has kind of become important for me to be able to do so.

Does anyone know how I can get this working? I can build it with no problem on Windows, so it's really just a matter of getting the library into a state where I can like it for a build on Linux.

2
dpkg -L libsdl2-2.0 should tellyou what it installed. You're likely to need libsdl2-2.0-dev too. The same goes for ttf and mixer, these are separate libraries.keltar

2 Answers

1
votes

The Ada compiler can only link against Ada libraries. It cannot link against arbitrary C libraries, like SDL2.

You will need to install something like sdlada.

0
votes

I found the solution, and as I expected, it was a total newbie thing.

After copying the .so produced by the SDL build process to the working directory, the mistake I made was to change the linker argument to the full filename of the .so (minus extension):

gnatmake -g main.adb -Isource -I../source/win -I../source -I../SDL2 -gnatwk -gnatwr -gnatwu -D objectFiles -largs -llibsdl2 -lSDL2_Mixer -lSDL2_ttf obj1.o obj2.o

What I needed to do was actually to leave it how it was:

gnatmake -g main.adb -Isource -I../source/win -I../source -I../SDL2 -gnatwk -gnatwr -gnatwu -D objectFiles -largs -lSDL2 -lSDL2_Mixer -lSDL2_ttf obj1.o obj2.o

After building SDL_Mixer and SDL_TTF, everything works as expected.