Linking with SDL3
  • Cocoon
    Cocoon
    Posts: 45 from 2018/6/9
    Could someone guide me on what linker params I should use for SDL3 please as I'm not having a lot of luck so far.

    I have a simple test application that creates a blank window and renderer, paints the window background and checks for quit or the escape key to exit. I figure if I'm going to try SDL then it may as well be SDL3. Converting the code from 2 to 3 was easy but I haven't managed to link the app yet.

    For SDL2 I have something like this (please note this is mostly typed, not copy/pasted so excuse any potential typos):
    Code:

    gcc -noixemul src/main.o gg:usr/local/lib/sdl2.a gg:ppc-morphos/lib/libnix/libGL.a

    That worked.

    For SDL3 I got (from sdl3-config):
    Code:

    gcc -noixemul src/main.o gg:usr/local/lib/sdl3.a gg:ppc-morphos/lib/libnix/libGL.a gg:ppc-morphos/lib/libpthread.a gg:ppc-morphos/lib/libc.a gg:ppc-morphos/lib/libm.a


    That spits out a bunch of errors, mostly about _ixbasearray.

    I'm not entirely new to C by any means but my main job is java so I'm not desperately familiar with all the different types of libs there are any why, for example, there are libb32 folders and so on.

    [ Edited by MartinW 18.05.2025 - 02:52 ]
  • »18.05.25 - 02:51
    Profile
  • Yokemate of Keyboards
    Yokemate of Keyboards
    Papiosaur
    Posts: 2402 from 2003/4/10
    From: France
    Hi MartinW,

    this is an example of Makefile for a SDL3 project i have ported:

    Code:
    #
    # Makefile for MorphOS C++ project
    #

    # Compiler and tools
    CC = ppc-morphos-gcc-11
    STRIP = ppc-morphos-strip

    # Build date for version info
    AMIGADATE = $(shell date +"%-d.%-m.%Y")
    DEFINE = -pthread -fsigned-char -D__AMIGADATE__=\"$(AMIGADATE)\"
    INCLUDE = -Iinclude
    -I/gg/usr/local/include
    -I/gg/usr/local/include/SDL3
    -I/gg/usr/local/include/SDL3_mixer
    -I/gg/usr/local/include/SDL3_ttf
    -I/gg/usr/local/include/SDL3_image

    # Compiler and linker flags
    CFLAGS = -noixemul -O2 -Wall -fsigned-char $(INCLUDE) $(DEFINE)
    LIBS = -noixemul -L/gg/usr/local/lib -lSDL3_mixer -lSDL3_image -lSDL3_ttf -lSDL3 -lGL -lstdc++ -pthread -lc -lm

    # Executable name
    TARGET = Wetris

    # Find all .cpp source files in src directory
    SRCS = $(wildcard src/*.c)

    # Generate corresponding object file names
    OBJS = $(SRCS:.c=.o)

    # Default target
    all: $(TARGET)

    # Link object files to create executable
    $(TARGET): $(OBJS)
    $(CC) $(LDFLAGS) $^ $(LIBS) -o $@
    # Uncomment to strip debug symbols:
    # $(STRIP) --strip-all $(TARGET)

    # Compile .c files to .o object files
    %.o: %.c
    $(CC) $(CFLAGS) -c $< -o $@

    # Remove all generated files
    clean:
    rm -f $(OBJS) $(TARGET)

    # Generate assembly dump for debugging
    dump:
    objdump --disassemble-all --reloc $(TARGET) > $(TARGET).s


    I hope could help you.
  • »18.05.25 - 03:18
    Profile Visit Website
  • Cocoon
    Cocoon
    Posts: 45 from 2018/6/9
    I think it might be that I'm lacking the flags '-pthread -fsigned-char', but I'm currently using Flow Studio and no matter where I add these in the settings they don't seem to get added to the Makefile. Maybe I'll go with my own Makefile and see if that helps.

    [EDIT] That works - thank you. Would be nice to work out how to get the same behaviour from Flow Studio but I can just use a custom Makefile for the moment.

    [ Edited by MartinW 18.05.2025 - 12:07 ]
  • »18.05.25 - 11:30
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    igracki
    Posts: 459 from 2003/2/25
    From: Berlin
    Quote:

    MartinW wrote:
    I think it might be that I'm lacking the flags '-pthread -fsigned-char', but I'm currently using Flow Studio and no matter where I add these in the settings they don't seem to get added to the Makefile. Maybe I'll go with my own Makefile and see if that helps.

    [EDIT] That works - thank you. Would be nice to work out how to get the same behaviour from Flow Studio but I can just use a custom Makefile for the moment.


    Did you try to add them to the Compiler Tab under C-Settings/defines in Project/Settings?
  • »18.05.25 - 13:46
    Profile Visit Website
  • Cocoon
    Cocoon
    Posts: 45 from 2018/6/9
    Quote:

    igracki wrote:
    Quote:

    MartinW wrote:
    I think it might be that I'm lacking the flags '-pthread -fsigned-char', but I'm currently using Flow Studio and no matter where I add these in the settings they don't seem to get added to the Makefile. Maybe I'll go with my own Makefile and see if that helps.

    [EDIT] That works - thank you. Would be nice to work out how to get the same behaviour from Flow Studio but I can just use a custom Makefile for the moment.


    Did you try to add them to the Compiler Tab under C-Settings/defines in Project/Settings?


    Pretty sure I did, yes. Should be able to check shortly.
  • »18.05.25 - 19:25
    Profile
  • Cocoon
    Cocoon
    Posts: 45 from 2018/6/9
    Not surprisingly, I think this is operator error. On multiple counts! The Flow UI is kind of confusing though in my defence.

    1: There are multiple places, seemingly to enter the same information. You have Project Settings, Compiler and Linker tabs. These appear to me to be completely ignored in favour of the same tabs under the specific target when you edit the target. I'm thinking maybe they specify some defaults though because the targets do seem to come pre-populated if I've already populated though tabs, apart from "Linker Libraries" that I don't think it understands (see point 3).

    2: I had specified gcc11 for the compiler and simply gcc (well, ppc-morphs-gcc) for the linker. That definitely caused at least one error / failure.

    3: Final and probably bigger one is the way that you enter the libraries in the linker tab. When I go to enter a library I have a little folder widget which brings up an ambient file browser and seems to expect me to pick an actual static library file such as `libSDL3.a`. Then it populates the full paths. That's fine but for a novice like me, I don't know which path to pick (libnix? libb32? etc.) and it all fails horribly. BUT, I just realised that instead of clicking the widget I can just enter the name as I would in a Makefile - '-lSDL3', '-lGL' and so on for each entry. Add -L/gg/etc as a linker flag and indeed it does then all seem to work just fine. But it feels like I'm not doing what the application is expecting there.

    I haven't got the hang of posting from MorphOS yet or I would include some screen shots to explain it better! I hope that makes some sense.
  • »18.05.25 - 20:51
    Profile
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    beworld
    Posts: 662 from 2010/2/10
    From: FRANCE
    SDL3 need pthread and gl only
    PowerMac G5 Quad 2.5, IMac G5 2.1, PowerBook G4 1.5, MacMini 1.5
    My MOS ports
  • »19.05.25 - 06:27
    Profile Visit Website
  • MorphOS Developer
    Nadir
    Posts: 173 from 2003/3/17
    Quote:

    MartinW wrote:
    Not surprisingly, I think this is operator error. On multiple counts! The Flow UI is kind of confusing though in my defence.



    Thanks for your feedback. I can see that it would be good with some documentation for people to get up to speed with how FlowStudio's build infrastructure works. Having said this, I really made a best effort to make the GUI easily accessible for simple projects while still making it possible to use it for really complex projects. I'm sure it's possible to improve on this but the trade-offs are not so easy.

    FlowStudio, as well as several other large MorphOS applications, are built using this functionality but I have also tested very simple projects so I'm quite confident it works more or less as intended ;-)

    Quote:


    1: There are multiple places, seemingly to enter the same information.

    You have Project Settings, Compiler and Linker tabs. These appear to me to be completely ignored in favour of the same tabs under the specific target when you edit the target. I'm thinking maybe they specify some defaults though because the targets do seem to come pre-populated if I've already populated though tabs, apart from "Linker Libraries" that I don't think it understands (see point 3).




    No, by default there is only one single place where you have to enter a given set of information. Unless you have specific needs, you should not even change target specific settings (which you get to by double clicking on a target). Moreover, until you have specifically ticked "Customized tool settings" for a target, the compiler and linker settings for a target will be shaded to indicate that the global settings will be used.

    Quote:


    2: I had specified gcc11 for the compiler and simply gcc (well, ppc-morphs-gcc) for the linker. That definitely caused at least one error / failure.



    That is a bit surprising. Typically, ppc-morphos-gcc should be able to link objects created by other versions of gcc as well. I haven't tested your specific case though

    Quote:


    3: Final and probably bigger one is the way that you enter the libraries in the linker tab. When I go to enter a library I have a little folder widget which brings up an ambient file browser and seems to expect me to pick an actual static library file such as `libSDL3.a`. Then it populates the full paths. That's fine but for a novice like me, I don't know which path to pick (libnix? libb32? etc.) and it all fails horribly. BUT, I just realised that instead of clicking the widget I can just enter the name as I would in a Makefile - '-lSDL3', '-lGL' and so on for each entry. Add -L/gg/etc as a linker flag and indeed it does then all seem to work just fine. But it feels like I'm not doing what the application is expecting there.



    This is an area where I had planned a more extensive GUI functionality (to list available link libraries and so on) but I never got around to implement it.The way it works now, it is best to just type e.g. -lGL manually if you want to use the default path but in case you have a custom linklib that you want to add, it might be convenient to use the ASL requester. For instance, in the FlowStudio link settings I have linklibs like "../../development/tools/astyle/build/gcc/bin/libastyle.a" which I added using the requester.

  • »19.05.25 - 09:15
    Profile
    • Cocoon
      Cocoon
      Posts: 45 from 2018/6/9
      It sounds like a case of I got there in the end as it certainly sounds like I’ve ended up specifying the libs in the way it was intended.

      Thanks for the application, I do appreciate it!

      I need to dig a bit deeper now as autocomplete doesn’t seem to work very well for SDL3. On SDL2 suggestions pop up nice and quick (I lowered the delay) but on SDL3 I seem to have to hit ctrl-space most of the time and there are often no suggestions. I assume this is nothing to do with flow studio and everything to do with SDL3 being a recent and beta port.

      Due to being new at this I might go back to SDL2 as I really am going to need to browse those suggestions
    • »19.05.25 - 11:27
      Profile