Mednafen Members Members   Search Search   Help Help   Register Register   Login Login   Home Home
Home » Mednafen » Development » Compiling mednafen for Windows
Show: Today's Messages  :: Show Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Compiling mednafen for Windows [message #6451] Wed, 19 May 2021 20:22 Go to next message
Yuri Bacon  [PM]
Over the last couple days I've been making a handfull of small changes to mednafen's source code for personal use (enable cheats in netplay, automatically record movies in netplay), and I've been able to make the changes I want then compile for and under linux (Ubuntu 20.04) just fine, and everything works. I now want to compile these changes for Windows, but I can't get it to compile. I have the same issues with or without my modifications.

I first tried cross compiling under Linux by doing (inside the mednafen folder, so ls would show me src and include and stuff):

./configure --host=x86_64-w64-mingw64
make


but get this problem:

In file included from ../../include/mednafen/mednafen.h:4,
                 from ../../include/mednafen/driver.h:4,
                 from main.h:4,
                 from main.cpp:18:
../../include/mednafen/types.h:141:3: error: #error "Bad configuration macros."
  141 |  #error "Bad configuration macros."
      |   ^~~~~
In file included from main.cpp:22:
../../include/mednafen/win32-common.h:25:10: fatal error: windows.h: No such file or directory
   25 | #include <windows.h>
      |          ^~~~~~~~~~~
compilation terminated.
make[2]: *** [Makefile:550: main.o] Error 1
make[2]: Leaving directory '/home/[redacted]/Mednafen Shit/mednafen test/src/drivers'
make[1]: *** [Makefile:4942: all-recursive] Error 1
make[1]: Leaving directory '/home/[redacted]/Mednafen Shit/mednafen test/src'
make: *** [Makefile:473: all-recursive] Error 1


I also tried using Cygwin under Windows 7, but when I run (in the same relative place):

./configure
make


I get this:

In file included from debugger.cpp:29:
memdebugger.h:25:10: fatal error: iconv.h: No such file or directory
   25 | #include <iconv.h>
      |          ^~~~~~~~~
compilation terminated.
make[2]: *** [Makefile:550: debugger.o] Error 1
make[2]: Leaving directory '/cygdrive/c/Users/[redacted]/Downloads/medtest/mednafen/src/drivers'
make[1]: *** [Makefile:4942: all-recursive] Error 1
make[1]: Leaving directory '/cygdrive/c/Users/[redacted]/Downloads/medtest/mednafen/src'
make: *** [Makefile:473: all-recursive] Error 1


I'm admittedly completely new to building anything for Windows, so maybe I'm just missing something super obvious, but I've looked at everything I can possibly find and I'm at a loss.

[Updated on: Wed, 19 May 2021 20:22]


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
she/her
Use my mednafen servers? Contact me! https://discord.gg/ngZuC9c8Wr
Play Digimon Rumble Arena: https://discord.gg/wg5j5Np
Re: Compiling mednafen for Windows [message #6452 is a reply to message #6451 ] Wed, 19 May 2021 22:39 Go to previous messageGo to next message
Administrator  [PM]
There are scripts in mednafen/mswin to build a cross-compiling toolchain on Linux( build-toolchain.sh ), and to compile Mednafen using that toolchain( build-mednafen.sh ).

Before running build-toolchain.sh, you'll need to install a few packages, download the prerequisite source tarballs into ~/mednafen-cross-sources and also copy mednafen/mswin/*.patch into that directory, and edit the GCC_CC and GCC_CXX variables at the top of the script to suit your system.

apt-get install build-essential pkg-config libmpfr-dev libgmp-dev libmpc-dev gawk

binutils-2.28.tar.bz2
flac-1.3.2.tar.xz
gcc-4.9.4.tar.bz2
libiconv-1.15.tar.gz
mingw-w64-v5.0.3.tar.bz2
SDL-2.0.8-11835.tar.gz (or a newer version, and edit PKGNAME_SDL2)
zlib-1.2.8.tar.gz

After the toolchain is compiled and installed, run build-mednafen.sh from the directory above the mednafen source directory, i.e. ./mednafen/mswin/build-mednafen.sh

Afterwards you can run ./mednafen/mswin/package-mednafen.sh though you'll probably want to edit the VERSION variable first.

[Updated on: Wed, 19 May 2021 22:51]

Re: Compiling mednafen for Windows [message #6453 is a reply to message #6452 ] Thu, 20 May 2021 01:09 Go to previous messageGo to next message
Yuri Bacon  [PM]
Thanks for the response! A folder called "mswin" seems obvious in hindsight, and I feel dumb for not looking at it.

Some of the info you posted was wrong (missed some tarballs, and they go in ~/toolchain-sources), but those three scripts were the missing thing that made it all click into place.

I've been able to get vanilla 1.26.1 to compile for Windows on my Linux computer now, so I do have everything in order. Having some problems getting my edits to compile, but that is on me at this point, and its pretty late now so I'm going to head off to bed and tackle it more in the morning.

Thank you so much!


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
she/her
Use my mednafen servers? Contact me! https://discord.gg/ngZuC9c8Wr
Play Digimon Rumble Arena: https://discord.gg/wg5j5Np
Re: Compiling mednafen for Windows [message #6650 is a reply to message #6453 ] Sat, 19 February 2022 23:42 Go to previous messageGo to next message
thezedman  [PM]
Sorry for the bump on this thread. I was able to get mednafen 1.29 to compile on a 32-bit version of Windows 7 running MinGW, and thought it would be helpful to share my approach.

Of note, I configured mine just to emulate Saturn and PC Engine, but assume (based on the troubleshooting it took to get the thing to compile and run) that it should work if you enable other emulation systems on the configure line.

1. Download and install MinGW (32-bit), and add the bin directory to the Windows shell PATH

2. Download pkg-config, dx80_mgw, glib, and portaudio-wasapi, and put the files into the appropriate MinGW directories

3. Run the following shell commands in the Windows Command Prompt to set the build envionment:
set CC=mingw32-gcc
set CXX=mingw32-g++
set LIBS=-liconv
set LDFLAGS=-liconv
set BINARY_PATH=C:\MinGW\bin
set LIBRARY_PATH=C:\MinGW\lib
set INCLUDE_PATH=C:\MinGW\include
set C_INCLUDE_PATH=C:\MinGW\include
set PKG_CONFIG=c:/MinGW/bin/pkg-config
set PKG_CONFIG_PATH=c:/MinGW/lib/pkgconfig


4. Copy C:\MinGW\bin\libintl-8.dll to C:\MinGW\bin\intl.dll

5. Download, compile and install zlib-1.2.11
cd zlib
copy win32\Makefile.gcc .
make --file=Makefile.gcc
make --file=Makefile.gcc install


6. Download, compile and install SDL 2.0.14
make install-package arch=i686-w64-mingw32 prefix=C:/MinGW


7. Add Xinput.h & sal.h to the C:\MinGW\include directory

8. Configure Mednafen (in my case I only needed PC Engine and Saturn support so I disabled everything else), *** be sure to use the --without-libiconv-prefix and --with-libflac=no options ***:
sh ./configure --prefix=C:/play/Saturn/mednafen-1.29 --exec-prefix=C:/play/Saturn/Mednafen-1.26 --host=mingw32 --enable-ss=yes --enable-altivec=no --enable-apple2=no --enable-gb=no --enable-gba=no --enable-lynx=no --enable-md=no --enable-nes=no --enable-ngp=no --enable-sms=no --enable-snes=no --enable-snes-faust=no --enable-vb=no --enable-wswan=no --enable-pcfx=no --enable-psx=no --enable-pce=yes --enable-pce-fast=yes  --without-libiconv-prefix --with-libflac=no


9. Copy the Mednafen source directory contents to C:\MinGW\include\mednafen

10. Change EWOULDBLOCK to WSAEWOULDBLOCK (Winsock version of the same error) in main.cpp and FileStream.cpp

11. Copy mkdir.exe from C:\MinGW\msys\1.0\bin to C:\MinGW\bin\mingw32-mkdir.exe, and change all instances of /usr/bin/mkdir to mingw32-mkdir in config.status

12. Change line 111 in shtypes.h by adding !defined(__unaligned):
#if defined(_M_IX86) || !defined(__unaligned)


13. Add the following to the start of to shtypes.h in the MinGW directory:
#include <rpcsal.h>


14. Add the following to wtypes.h in MinGW directory, after "_BEGIN_C_DECLS":
typedef struct _tagpropertykey {
 	GUID  fmtid;
 	DWORD pid;
 } PROPERTYKEY;
 
 /* Byte blob */
 typedef struct _BYTE_BLOB {
     unsigned long   clSize;
     byte            abData[1];
 } BYTE_BLOB;
 typedef BYTE_BLOB   *UP_BYTE_BLOB;
 
 /* Word blob */
 typedef struct _WORD_BLOB {
     unsigned long   clSize;
     unsigned short  asData[1];
 } WORD_BLOB;
 typedef WORD_BLOB   *UP_WORD_BLOB;
 
 /* Double word blob */
 typedef struct _DWORD_BLOB {
     unsigned long   clSize;
     unsigned long   alData[1];
 } DWORD_BLOB;
 typedef DWORD_BLOB  *UP_DWORD_BLOB;


15. In C:\MinGW\include\objidl.h add the following after typedef IPropertyStorage and IPropertySetStorage, respectively
    #define __IPropertyStorage_INTERFACE_DEFINED__
    #define __IPropertySetStorage_INTERFACE_DEFINED__


16. Add the following two lines after 'DECLARE_ENUMERATOR(STATPROPSTG);' in C:\MinGW\include\objidl.h:
     #define __IEnumSTATPROPSETSTG_INTERFACE_DEFINED__
     #define __IEnumSTATPROPSTG_INTERFACE_DEFINED__


17. Add the following line to C:\MinGW\audioclient.h near the other similar definitions
#define AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED AUDCLNT_ERR(0x19)


18. Comment out '#include <audiopolicy.h>' in Mednafen's wasapi.cpp and wasapish.cpp

19. Add the following to Mednafen's Time_Win32.cpp:
     typedef struct _TIME_DYNAMIC_ZONE_INFORMATION {
           LONG       Bias;
           WCHAR      StandardName[32];
           SYSTEMTIME StandardDate;
           LONG       StandardBias;
           WCHAR      DaylightName[32];
           SYSTEMTIME DaylightDate;
           LONG       DaylightBias;
           WCHAR      TimeZoneKeyName[128];
           BOOLEAN    DynamicDaylightTimeDisabled;
     } DYNAMIC_TIME_ZONE_INFORMATION, *PDYNAMIC_TIME_ZONE_INFORMATION;


20. Comment out the following two include lines in Time_Win32.cpp:
      //#include <wspiapi.h>
      //#include <strsafe.h>


21. Comment out the following in main.cpp, otherwise it will compile but not work with any Windows other than Windows 98 or ME:
        /*if(!(GetVersion() & 0x80000000))
        {
	 const char* errorstr = _("This special build of Mednafen is intended for use on Windows 98, Windows 98SE, and Windows Me.  It will perform suboptimally on NT-based versions of Windows.  Download a regular Windows build from https://mednafen.github.io/releases/");

	 if(!SuppressErrorPopups)
	  MessageBoxA(NULL, errorstr, "Mednafen Windows Version Error", MB_OK | MB_ICONSTOP | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST);

	 printf("%s\n", errorstr);

	 return -1;
        }*/


22. Comment out the following lines in test.cpp (otherwise it won't run!)
//CheckAlignasI_Sub<I>((void*)lv0);
 //CheckAlignasI_Sub<I>((void*)lv1);
 


Finally run mingw32-make, and it should compile mednafen.exe in the src directory. You can then choose to either run mingw32-make install, or simply just copy the exe file to any directory and run Mednafen.

Note that there may be some bugs running a version of Mednafen compiled using this approach, but so far it seems to run okay (including the "experimental 64-bit Sega Saturn code" on my 32-bit Windows computer!)

Re: Compiling mednafen for Windows [message #7005 is a reply to message #6451 ] Fri, 19 January 2024 07:16 Go to previous message
noFate  [PM]
Have anybody tried to compile Mednafen on IDEs like CodeBlocks? I want to modify Mednafen sources and run it for debugging. But I really got stuck. So, guys, if you have any ideas please help.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic:Pop'n Music controller support?
Next Topic:Crash after building with msys2 mingw64 on windows x64
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ ]

Current Time: Sat May 4 22:12:56 CDT 2024
.:: Contact :: Home ::.

Powered by FUDforum.
Copyright © FUDforum Bulletin Board Software