0

I've been having trouble compiling an executable with SDL 1.2 and C that will work on another machine. I'vee been compiling it from Ubuntu using a makefile. I'd like to be able to send a "bin.zip" to a classmate, with "SDL.dll" and "SDL_ttf.dll" inside as well as "prog" the executable that I compiled for them.

I would expect them to be able to run that "prog" from their own Ubuntu desktop (Virtual Machine, if that's relevant) and not need to install libsdl1.2debian and libsdl-ttf2.0-0 themselves first, since I included the DLLs.

Note that they can run it fine once they've installed those libraries.

My project structure, at compilation, is such:

  • 2048-c
    • /bin (dlls and executable)
    • /include (".h" header files)
    • /lib ("SDL.lib", "SDL_ttf.lib", "SDLmain.lib")
    • /src (".c" source files)
    • "makefile"

My makefile looks like this:

CC=gcc

CFLAGS=-c -Wall `sdl-config --cflags`
LDFLAGS=`sdl-config --libs` -lSDL_ttf
SOURCES=src/main.c src/toolbox.c src/game.c
OBJECTS=$(SOURCES:.c=.o)
EXECUTABLE=bin/prog

.PHONY: clean
all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
    $(CC) $(OBJECTS) $(LDFLAGS) -o $@
.c.o:
    $(CC) $(CFLAGS) $< -o $@

clean:
    rm -f $(OBJECTS) $(EXECUTABLE)

Am I missing something obvious? Edit: (Yes, I was)

  • 2
    It looks like you're building for Linux, but then you mention `.dll` files which are Windows shared libraries. – Some programmer dude Dec 14 '21 at 14:05
  • 1
    If you really want to be able to run an executable built on one Linux system on another Linux system you should try to link *statically*. Add `-static` when linking. It might still not work, as some libraries can't be linked statically, and there might be ABI differences between the two systems. But at least there's a bigger chance than linking dynamically (the default) and attempting to use Windows DLL's. – Some programmer dude Dec 14 '21 at 14:07
  • Jus tin case you are compiling on a Linux machine try to compiling for Windows targets, you need to cross compile. I think you can use the package gcc-mingw-w64 on Ubuntu for that. Here I once had similar plans: https://stackoverflow.com/questions/34795694/how-to-cross-compile-with-sdl-2-from-linux-for-windows – Danny Raufeisen Dec 14 '21 at 14:12
  • > It looks like you're building for Linux, but then you mention .dll files which are Windows shared libraries That'll be the obvious thing I'm missing. Dang. thanks. And thanks Danny – AlexFroggyD Dec 14 '21 at 14:19
  • Welcome to StackOverflow! Please take the [tour] and read some of the [help] to learn how this site works. It is not a forum. -- Is your question answered? If so, please add an answer and later mark it. If not, [edit] your question and clarify. – the busybee Dec 14 '21 at 14:43
  • You might wanna build SDL2 yourself, instead of taking it from some repos. At least on Ubuntu, the repo version disables detecting and choosing available libraries at runtime, instead hardcoding the dependencies. This should make your code more portable. – HolyBlackCat Dec 14 '21 at 17:15
  • On Linux, shared libs next to the executable are not considered for loading by default. If you're gonna distribute SDL2 (and other libs) with your app this way, you'll need to do something about it. Either set [RPATH](https://en.wikipedia.org/wiki/Rpath) (for your own app using the linker flags, and for prebuilt libraries using `patchelf`), or using a separate launcher script that sets `LD_LIBRARY_PATH`. – HolyBlackCat Dec 14 '21 at 17:17
  • I appreciate it. It's actually SDL 1.2, but your point is still relevant. I'll look into that – AlexFroggyD Dec 14 '21 at 18:28

1 Answers1

0

Yes, I was missing something obvious : DLLs are specifically for Windows

Now, as for getting an executable to work without installing the required libraries, I still haven't managed that (linking statically didn't pan out, in my case), but at least I learnt something.

If I give cross-compilation to Windows a try, I'll try to update this.