Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling with mingw32 and SDL 1.2 as console application #22

Closed
dmitrysmagin opened this issue Mar 25, 2023 · 2 comments
Closed

Compiling with mingw32 and SDL 1.2 as console application #22

dmitrysmagin opened this issue Mar 25, 2023 · 2 comments

Comments

@dmitrysmagin
Copy link
Contributor

dmitrysmagin commented Mar 25, 2023

Hi.
It's possible to compile a console application with mingw32, though you need some manual config

  1. I needed to create a ./m4 subfolder and put pkg.m4 inside in order to configure properly. I used this https://github.com/pkgconf/pkgconf/blob/master/pkg.m4 and changed Makefile.am and configure.ac accordingly:
diff --git a/Makefile.am b/Makefile.am
index dd9a7fc..66ea5e4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,3 +3,5 @@ SUBDIRS = src doc
 EXTRA_DIST = adplay.spec adplay.qpg

 AUTOMAKE_OPTIONS = dist-bzip2
+
+ACLOCAL_AMFLAGS = -I m4
diff --git a/configure.ac b/configure.ac
index 565acb2..cdb8938 100644
--- a/configure.ac
+++ b/configure.ac
@@ -15,6 +15,8 @@ AC_PROG_CXX
 AC_PROG_CPP
 AC_PROG_CXXCPP

+AC_CONFIG_MACRO_DIRS([m4])
+
 # Nothing works without these libraries...
 AC_CHECK_LIB(stdc++,main,,AC_MSG_ERROR([libstdc++ not installed]))
 PKG_CHECK_MODULES([adplug], [adplug >= 2.0],,[

Only after that the command autoreconf --install finished successfully

  1. After that I was able to execute ./configure --prefix=/mingw CXXFLAGS=-fpermissive. But before configuring it's better to fix SDL (below)

  2. SDL config problem. By default sdl-config script forces your application to be a windows app, not console, and it intercepts output to sderr and stdout and redirects it into files.
    I've found if you edit sdl-config the configure will fail (sdl won't be found) so I had to edit the resulting Makefile in the following way: removed -Dmain=SDL_main and -lSDLmain and changed -mwindows into -mconsole
    Another important thing: insert #undef main in the adplug.cc right before the main().

  3. sdl.h header problem.
    As noted in another issue, windows fs is not case-sensitive, so #include <SDL.h> and #include "sdl.h" are misinterpreted as 'include local sdl.h` by the compiler. To overcome this, better rename ./src/sdl.h into ./src/sdlx.h and change all #includes accordingly

  4. Strange typecast is needed in adplug.cc:

diff --git a/src/adplay.cc b/src/adplay.cc
index d93d16f..2973ca0 100644
--- a/src/adplay.cc
+++ b/src/adplay.cc
@@ -239,7 +239,7 @@ static int decode_switches(int argc, char **argv)
     {NULL, 0, NULL, 0}                         // end of options
   };

-  while ((c = getopt_long(argc, argv, "8f:b:d:irms:ol:hVe:O:D:qv",
+  while ((c = getopt_long(argc, (char* const** (*)())argv, "8f:b:d:irms:ol:hVe:O:D:qv",
                          long_options, (int *)0)) != EOF) {
       switch (c) {
       case '8': cfg.bits = 8; break;

After all above the make will succeed and the resulting adplay.exe will show output in the console

dmitrysmagin@3f1135a

@mywave82
Copy link
Contributor

Can you please create some PRs?

  • update aclocal to use m4/ directory and put initial needed m4 files there, including pkg.m4

  • getopt.h getopt1.c should probably be updated to receive char *const argv[] which is what GNU libc getopt_long() implementation expect, removing the need to that typecast

  • rename sdl.h to avoid name-clash (we can probably expect that different compilers to have different order of include directories)

Add support for SDL2.0 and fallback to SDL1.2. For audio I believe the API is identical, and perhaps fixes a couple of the issues.

@dmitrysmagin
Copy link
Contributor Author

Created PR: #23

@mywave82 mywave82 closed this as completed Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants