Compiling SDL2 in MSYS2 with sound?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AnonymousHero
    Veteran
    • Jun 2007
    • 1322

    #16
    Try running "strip" on the executable post-build.

    Comment

    • smbhax
      Swordsman
      • Oct 2021
      • 325

      #17
      Originally posted by AnonymousHero
      Try running "strip" on the executable post-build.
      Ooh! "strip angband.exe" gets it down to 11.5 MB, with or without setting -g0 in the Makefile. : )
      My Angband videos

      Comment

      • Pete Mack
        Prophet
        • Apr 2007
        • 6697

        #18
        Strip is a bad choice. You won't be able to report bugs. Use -O2 optimization. It'll make a clean build. If you can find a static build of the SDL library you'll do better, too.

        Comment

        • smbhax
          Swordsman
          • Oct 2021
          • 325

          #19
          Aw. Well, it's already got -O2 in there, at least.
          My Angband videos

          Comment

          • smbhax
            Swordsman
            • Oct 2021
            • 325

            #20
            Not sure about the "static build of the SDL library" thing. Googling suggests static linking the SDL2 library is a little involved. These pages for instance

            https://stackoverflow.com/questions/...linking-errors (2022)
            https://stackoverflow.com/questions/...sdl2-libraries (2013)

            which are not MSYS2-specific, mention a lot of additional linker flags, and something about special handling surrounding a "libSDL2.a" file. Well, the main 2022 answer seems to be

            If you want to link SDL2 dynamically (this should be your default course of action), you need to add libSDL2.dll.a to your library directory. Then libSDL2.a will be ignored and can be removed. It should just work, no other changes are needed.
            No idea if any of that applies to MSYS2 though. This stuff is a bit over my head.

            There's also this page

            I want to make a game using SDL2, but I'm unable to compile and/or run my code, please help! SDL2 is notoriously hard to set up, and it's often the first library aspiring game developers try to use.


            which does have a section on MSYS2, titled "A saner alternative":

            Install SDL2 from its package manager. Use a tool called pkg-config (also from the package manager) to automatically determine all necessary flags (pkg-config --cflags SDL2 for compiler flags, pkg-config --libs SDL2 for linker flags).

            This is the same experience as you would have on Linux (maybe except for some DLL management hassle)
            Last edited by smbhax; November 20, 2022, 02:42.
            My Angband videos

            Comment

            • smbhax
              Swordsman
              • Oct 2021
              • 325

              #21
              My MSYS2 install seems to have something called pkgconf instead of pkg-config; when I tell it to install pkg-config, it says it could conflict with pkgconf. Here's what I get using pkgconf on the SDL2 packages:

              smbhax@DESKTOP-64GQN1N MINGW64 ~/angband
              $ pkgconf --cflags sdl2
              -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/SDL2 -Dmain=SDL_main

              smbhax@DESKTOP-64GQN1N MINGW64 ~/angband
              $ pkgconf --cflags sdl2_image
              -IC:/msys64/mingw64/include/SDL2 -IC:/msys64/mingw64/include -Dmain=SDL_main -IC:/msys64/mingw64/include/libpng16 -DHWY_SHARED_DEFINE

              smbhax@DESKTOP-64GQN1N MINGW64 ~/angband
              $ pkgconf --cflags sdl2_mixer
              -IC:/msys64/mingw64/include/SDL2 -IC:/msys64/mingw64/include -Dmain=SDL_main -IC:/msys64/mingw64/include/opus

              smbhax@DESKTOP-64GQN1N MINGW64 ~/angband
              $ pkgconf --cflags sdl2_ttf
              -IC:/msys64/mingw64/include/SDL2 -IC:/msys64/mingw64/include -Dmain=SDL_main -IC:/msys64/mingw64/include/harfbuzz -IC:/msys64/mingw64/include/freetype2 -IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include/glib-2.0 -IC:/msys64/mingw64/lib/glib-2.0/include

              smbhax@DESKTOP-64GQN1N MINGW64 ~/angband
              $ pkgconf --libs sdl2
              -LC:/msys64/mingw64/lib -lmingw32 -mwindows -lSDL2main -lSDL2

              smbhax@DESKTOP-64GQN1N MINGW64 ~/angband
              $ pkgconf --libs sdl2_image
              -LC:/msys64/mingw64/lib -lSDL2_image -lmingw32 -mwindows -lSDL2main -lSDL2

              smbhax@DESKTOP-64GQN1N MINGW64 ~/angband
              $ pkgconf --libs sdl2_mixer
              -LC:/msys64/mingw64/lib -lSDL2_mixer -lmingw32 -mwindows -lSDL2main -lSDL2

              smbhax@DESKTOP-64GQN1N MINGW64 ~/angband
              $ pkgconf --libs sdl2_ttf
              -LC:/msys64/mingw64/lib -lSDL2_ttf -lmingw32 -mwindows -lSDL2main -lSDL2

              Some of those linker flags aren't in the Makefile, like -lmingw32, -mwindows, -lSDL2main and -lSDL2. But I have no idea if that's relevant. There are quite a few flags in the SDL2 flag sections of the Makefile that weren't listed by pkgconf, but I don't know if those are just other things Angband needs to support its use of SDL2. And I don't know where to look for the cflags exactly; I see some things like -harfbuzz in the Makefile ("-freetype" is in twice for some reason--Oh maybe that has to do with "# freetype and harfbuzz has Circular dependency"), but not others like libpng16 or glib-2.0 (and -DHWY_SHARED_DEFINE?).

              (Oh realized Angband doesn't use SDL2_gfx; removed that.)
              Last edited by smbhax; November 20, 2022, 02:51.
              My Angband videos

              Comment

              • backwardsEric
                Knight
                • Aug 2019
                • 530

                #22
                Makefile.msys.sdl2 runs sdl2-config (i.e. "sdl2-config --cflags", "sdl2-config --static-libs", "sdl2-config --libs") to query the installed SDL2 for what flags are needed. The additional libraries listed in Makefile.msys2.sdl2 are there to satisfy the statically linked build (sdl2-config and, likely, pkgconf don't report the libraries needed for SDL2's dependencies).

                Comment

                • smbhax
                  Swordsman
                  • Oct 2021
                  • 325

                  #23
                  sdl2-config doesn't seem to give me a lot, I guess it does get -lSDL2 from that though. "sdl2-config --static-libs" doesn't seem to work:

                  smbhax@DESKTOP-64GQN1N ~
                  $ sdl2-config --cflags
                  -I/usr/include/SDL2 -D_REENTRANT

                  smbhax@DESKTOP-64GQN1N ~/angband
                  $ sdl2-config --static-libs
                  Usage: /usr/bin/sdl2-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]

                  smbhax@DESKTOP-64GQN1N ~/angband
                  $ sdl2-config --libs
                  -L/usr/lib -lSDL2
                  My Angband videos

                  Comment

                  Working...
                  😀
                  😂
                  🥰
                  😘
                  🤢
                  😎
                  😞
                  😡
                  👍
                  👎