audetto / AppleWin

Apple II emulator for Linux
GNU General Public License v2.0
49 stars 12 forks source link

libretro: compilation on Windows & MSYS2 #49

Open audetto opened 2 years ago

audetto commented 2 years ago

It was mentioned here that the libretro code does not compile on Windows with MSYS2

https://github.com/audetto/AppleWin/issues/44#issuecomment-980778592

I am allergic to Windows, but in small doses I could do something. Is there any interest out there?

I could try to make it compile using Visual Studio 2019 (same compiler used by AW). Any interest?

gouchi commented 3 months ago

I tried to make a quick using msys2 and I got using

git clone https://github.com/audetto/AppleWin.git --recursive
mkdir build
cd build/
cmake -DCMAKE_BUILD_TYPE=RELEASE  -DBUILD_LIBRETRO=ON ..
-- The C compiler identification is GNU 14.1.0
-- The CXX compiler identification is GNU 14.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMAKE_BUILD_TYPE:                RELEASE
CMAKE_CXX_FLAGS:
CMAKE_CXX_FLAGS_RELEASE:         -O3 -DNDEBUG
CMAKE_CXX_FLAGS_DEBUG:           -g
CMAKE_CXX_FLAGS_RELWITHDEBINFO:  -O2 -g -DNDEBUG
-- Found PkgConfig: /mingw64/bin/pkg-config.exe (found version "2.2.0")
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
  Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake/Modules/FindZLIB.cmake:202 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  source/CMakeLists.txt:4 (find_package)

-- Configuring incomplete, errors occurred!

I installed RA environnement packages even not necessary (I did not install Nvdia and QT packages). Here the list at the end packages.txt.

audetto commented 3 months ago

When you compile this libretro core, you need to install its dependencies, which are not the ones listed there.

I have a list of dependencies for Fedora (https://github.com/audetto/AppleWin/blob/master/source/linux/fedora.list.txt) and Debian (https://github.com/audetto/AppleWin/blob/master/source/linux/raspbian.list.txt).

If you restrict to libretro you might be able to skip some.

gouchi commented 3 months ago

I was missing packages zlib-devel mingw-w64-x86_64-minizip mingw-w64-x86_64-libslirp mingw-w64-x86_64-libyaml mingw-w64-x86_64-boost

CMake is ok now

cmake -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_LIBRETRO=ON ..
-- The C compiler identification is GNU 14.1.0
-- The CXX compiler identification is GNU 14.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMAKE_BUILD_TYPE:                RELEASE
CMAKE_CXX_FLAGS:
CMAKE_CXX_FLAGS_RELEASE:         -O3 -DNDEBUG
CMAKE_CXX_FLAGS_DEBUG:           -g
CMAKE_CXX_FLAGS_RELWITHDEBINFO:  -O2 -g -DNDEBUG
-- Found PkgConfig: /mingw64/bin/pkg-config.exe (found version "2.2.0")
-- Found ZLIB: /usr/lib/libz.dll.a (found version "1.3.1")
-- Checking for one of the modules 'yaml-0.1'
-- Checking for one of the modules 'minizip'
-- Checking for one of the modules 'slirp'
CMake Warning (dev) at source/CMakeLists.txt:34 (find_package):
  Policy CMP0167 is not set: The FindBoost module is removed.  Run "cmake
  --help-policy CMP0167" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found Boost: /mingw64/lib/cmake/Boost-1.85.0/BoostConfig.cmake (found version "1.85.0")
CMake Warning (dev) at source/frontends/common2/CMakeLists.txt:36 (find_package):
  Policy CMP0167 is not set: The FindBoost module is removed.  Run "cmake
  --help-policy CMP0167" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found Boost: /mingw64/lib/cmake/Boost-1.85.0/BoostConfig.cmake (found version "1.85.0") found components: program_options
-- Configuring done (15.6s)
-- Generating done (0.6s)
-- Build files have been written to: /home/gouchi/AppleWin/build

But now I getting this error :

[  1%] Building CXX object source/linux/libwindows/CMakeFiles/windows.dir/dmusicc.cpp.o
In file included from C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/winhandles.h:3,
                 from C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/dmusicc.h:3,
                 from C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/dmusicc.cpp:1:
C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/wincompat.h:47:9: warning: "__int64" redefined
   47 | #define __int64 long long int
      |         ^~~~~~~
In file included from C:/Users/krimo/Downloads/msys2/mingw64/include/corecrt.h:10,
                 from C:/Users/krimo/Downloads/msys2/mingw64/include/crtdefs.h:10,
                 from C:/Users/krimo/Downloads/msys2/mingw64/include/stdint.h:28,
                 from C:/Users/krimo/Downloads/msys2/mingw64/lib/gcc/x86_64-w64-mingw32/14.1.0/include/stdint.h:9,
                 from C:/Users/krimo/Downloads/msys2/mingw64/include/c++/14.1.0/cstdint:45,
                 from C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/wincompat.h:20:
C:/Users/krimo/Downloads/msys2/mingw64/include/_mingw.h:241:9: note: this is the location of the previous definition
  241 | #define __int64 long long
      |         ^~~~~~~
C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/wincompat.h:193:9: warning: "__stdcall" redefined
  193 | #define __stdcall
      |         ^~~~~~~~~
<built-in>: note: this is the location of the previous definition
C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/wincompat.h:203:9: warning: "__forceinline" redefined
  203 | #define __forceinline inline
      |         ^~~~~~~~~~~~~
C:/Users/krimo/Downloads/msys2/mingw64/include/_mingw.h:264:9: note: this is the location of the previous definition
  264 | #define __forceinline inline __attribute__((__always_inline__))
      |         ^~~~~~~~~~~~~
[  1%] Building CXX object source/linux/libwindows/CMakeFiles/windows.dir/dsound.cpp.o
In file included from C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/winhandles.h:3,
                 from C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/dsound.h:3,
                 from C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/dsound.cpp:1:
C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/wincompat.h:47:9: warning: "__int64" redefined
   47 | #define __int64 long long int
      |         ^~~~~~~
In file included from C:/Users/krimo/Downloads/msys2/mingw64/include/corecrt.h:10,
                 from C:/Users/krimo/Downloads/msys2/mingw64/include/crtdefs.h:10,
                 from C:/Users/krimo/Downloads/msys2/mingw64/include/stdint.h:28,
                 from C:/Users/krimo/Downloads/msys2/mingw64/lib/gcc/x86_64-w64-mingw32/14.1.0/include/stdint.h:9,
                 from C:/Users/krimo/Downloads/msys2/mingw64/include/c++/14.1.0/cstdint:45,
                 from C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/wincompat.h:20:
C:/Users/krimo/Downloads/msys2/mingw64/include/_mingw.h:241:9: note: this is the location of the previous definition
  241 | #define __int64 long long
      |         ^~~~~~~
C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/wincompat.h:193:9: warning: "__stdcall" redefined
  193 | #define __stdcall
      |         ^~~~~~~~~
<built-in>: note: this is the location of the previous definition
C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/wincompat.h:203:9: warning: "__forceinline" redefined
  203 | #define __forceinline inline
      |         ^~~~~~~~~~~~~
C:/Users/krimo/Downloads/msys2/mingw64/include/_mingw.h:264:9: note: this is the location of the previous definition
  264 | #define __forceinline inline __attribute__((__always_inline__))
      |         ^~~~~~~~~~~~~
[  2%] Building CXX object source/linux/libwindows/CMakeFiles/windows.dir/fileapi.cpp.o
In file included from C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/fileapi.h:3,
                 from C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/fileapi.cpp:1:
C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/wincompat.h:47:9: warning: "__int64" redefined
   47 | #define __int64 long long int
      |         ^~~~~~~
In file included from C:/Users/krimo/Downloads/msys2/mingw64/include/corecrt.h:10,
                 from C:/Users/krimo/Downloads/msys2/mingw64/include/crtdefs.h:10,
                 from C:/Users/krimo/Downloads/msys2/mingw64/include/stdint.h:28,
                 from C:/Users/krimo/Downloads/msys2/mingw64/lib/gcc/x86_64-w64-mingw32/14.1.0/include/stdint.h:9,
                 from C:/Users/krimo/Downloads/msys2/mingw64/include/c++/14.1.0/cstdint:45,
                 from C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/wincompat.h:20:
C:/Users/krimo/Downloads/msys2/mingw64/include/_mingw.h:241:9: note: this is the location of the previous definition
  241 | #define __int64 long long
      |         ^~~~~~~
C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/wincompat.h:193:9: warning: "__stdcall" redefined
  193 | #define __stdcall
      |         ^~~~~~~~~
<built-in>: note: this is the location of the previous definition
C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/wincompat.h:203:9: warning: "__forceinline" redefined
  203 | #define __forceinline inline
      |         ^~~~~~~~~~~~~
C:/Users/krimo/Downloads/msys2/mingw64/include/_mingw.h:264:9: note: this is the location of the previous definition
  264 | #define __forceinline inline __attribute__((__always_inline__))
      |         ^~~~~~~~~~~~~
C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/fileapi.h:43:9: warning: "_MAX_EXT" redefined
   43 | #define _MAX_EXT            _MAX_FNAME
      |         ^~~~~~~~
In file included from C:/Users/krimo/Downloads/msys2/mingw64/include/c++/14.1.0/cstdlib:79,
                 from C:/Users/krimo/Downloads/msys2/mingw64/include/c++/14.1.0/stdlib.h:36,
                 from C:/Users/krimo/Downloads/msys2/mingw64/include/assert.h:17,
                 from C:/Users/krimo/Downloads/msys2/mingw64/include/c++/14.1.0/cassert:44,
                 from C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/wincompat.h:21:
C:/Users/krimo/Downloads/msys2/mingw64/include/stdlib.h:123:9: note: this is the location of the previous definition
  123 | #define _MAX_EXT 256
      |         ^~~~~~~~
C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/fileapi.cpp: In function 'DWORD GetFullPathName(const char*, DWORD, char*, char**)':
C:/Users/krimo/Downloads/msys2/home/krimo/AppleWin/source/linux/libwindows/fileapi.cpp:133:25: error: 'realpath' was not declared in this scope
  133 |   const char * result = realpath(filename, buffer);
      |                         ^~~~~~~~
make[2]: *** [source/linux/libwindows/CMakeFiles/windows.dir/build.make:104: source/linux/libwindows/CMakeFiles/windows.dir/fileapi.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:196: source/linux/libwindows/CMakeFiles/windows.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
audetto commented 3 months ago

unfortunately, my Windows on qemu is barely usable, and msys2 does not really work on wine.

so, at the moment I struggle to replicate your build environment.

anyway, I am not surprised that a lot of the content of libwindows clashes with a real Windows compiler. you will have to try to tweak until you get something decent.

meanwhile I will keep trying to install msys2 somewhere.

gouchi commented 3 months ago

Not sure as a workaround/temporary solution, you could use Github actions ?

audetto commented 2 months ago

Hi,

I've finally managed to get a working msys2.

If you want this to work, there is a big decision to take: are you pretending to be in a _MSC_VER situation or not? Or, which is more or less the same, are you going to include the real windows.h or not?

If you include the real windows.h, then you need to remove all my compatibility layer libwindows.

Otherwise, you pretend you are in a linux-like environment and include my libwindows, but msys2 already provides a lot of the CRT-like functions, typedefs and macros which I have redefined in libwindows. They will have to be #ifdef'd out for msys2.

So, one might think it is a lot better to include the real windows.h and avoid my re-implementations.

This is not possible, because libwindows offers an interface for various features which in the real AppleWin go directly to the real implementation in Windows

AppleWin lacks a system independent abstraction for the above, which is what my libwindows effectively does.

So, right now, I think it would be easier to pretend you are in a linux-like environment, and never ever include the real windows.h, but split my libwindows in 2: windows and crt, since the latter is already provided by msys2 (which is almost impossible not to link to).

audetto commented 2 months ago

Moreover, the behaviour might depend on the chosen environment https://www.msys2.org/docs/environments/

retroarch suggests mingw64.

audetto commented 2 months ago

I've tried a bit more.

Basically a lot of the #ifdef _MSC_VER should be converted to something like if using a windows api, as they have nothing to do with the compiler.

it is really a hybrid environment, not a quick win.