Skip to content

Instantly share code, notes, and snippets.

@matcool
Last active June 9, 2024 13:12
Show Gist options
  • Save matcool/abb65ee59ded3766717c673014c3a2a7 to your computer and use it in GitHub Desktop.
Save matcool/abb65ee59ded3766717c673014c3a2a7 to your computer and use it in GitHub Desktop.

Guide for cross compiling Windows GD Mods on Linux

Requirements

  • clang & llvm (make sure you have clang-cl)
  • cmake (duh)
  • git

1. Setting up xwin

Install xwin, you can also just use one of the unknown-linux tarballs from the releases

Now decide where you want your splat folder to be (this is the folder with the windows sdk and msvc headers/libs). For this guide i'll be using ~/splat to refer to this directory

Now run this command to download and extract all the headers:

xwin --arch x86_64 --accept-license splat --include-debug-libs --output splat

2. Clone the toolchain

Clone the clang-msvc-sdk repo, which contains the cmake toolchain file. For this guide i'll be using ~/toolchain to refer to the directory of the repo

git clone https://github.com/matcool/clang-msvc-sdk.git toolchain

3. Building

Since configuring the toolchain requires a lot of enviroment vars, i'll be creating a bash script with them.

Run this in the directory of your own CMake project of course..

build.sh

# remember to actually set these..
export SPLAT_DIR=/home/mat/splat
export TOOLCHAIN=/home/mat/toolchain/clang-cl-msvc.cmake
export HOST_ARCH=x86_64

# you can also use `-G Ninja` here
cmake \
  -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN \
  -DCMAKE_BUILD_TYPE=Release \
  -B build
  
cmake --build build --config Release

additional notes

Apparently the newer msvc stls require clang 16+, at least i got an error with clang 15 :(

These were all the packages i had to install on ubuntu to get this to work

sudo apt install git cmake clang-17 clang-tools-17 lld-17
@B1rtek
Copy link

B1rtek commented Jan 25, 2024

One note: if the path to your Geode project contains a space, this doesn't work for some reason, failing with a following error:

-- Found SPLAT_DIR: /mnt/d/Kody/GeodeLinux/splat
-- Found HOST_ARCH: x86
-- "LLVM_VER" not set, leaving blank
-- "CLANG_VER" not set, leaving blank
-- "LLVM_PATH" not set, leaving blank
-- "LLVM_VER" not set, leaving blank
-- "CLANG_VER" not set, leaving blank
-- "LLVM_PATH" not set, leaving blank
-- The C compiler identification is Clang 16.0.6 with MSVC-like command-line
-- The CXX compiler identification is Clang 16.0.6 with MSVC-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/bin/clang-cl
-- Check for working C compiler: /usr/bin/clang-cl - broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "/usr/bin/clang-cl"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: '/mnt/d/Kody/C++ Projects/Test/build/CMakeFiles/CMakeScratch/TryCompile-bKMrc7'
    
    Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/make -f Makefile cmTC_4c27c/fast
    /usr/bin/make  -f CMakeFiles/cmTC_4c27c.dir/build.make CMakeFiles/cmTC_4c27c.dir/build
    make[1]: Wejście do katalogu '/mnt/d/Kody/C++ Projects/Test/build/CMakeFiles/CMakeScratch/TryCompile-bKMrc7'
    Building C object CMakeFiles/cmTC_4c27c.dir/testCCompiler.c.obj
    /usr/bin/clang-cl  /nologo   -Xclang -fexceptions -Xclang -fcxx-exceptions -Xclang -D_CRT_SECURE_NO_WARNINGS --target=i686-windows-msvc -fms-compatibility-version=19.11 -Wno-unused-command-line-argument -imsvc /mnt/d/Kody/GeodeLinux/splat/crt/include -imsvc /mnt/d/Kody/GeodeLinux/splat/sdk/include/ucrt -imsvc /mnt/d/Kody/GeodeLinux/splat/sdk/include/shared -imsvc /mnt/d/Kody/GeodeLinux/splat/sdk/include/um -imsvc /mnt/d/Kody/GeodeLinux/splat/sdk/include/winrt -Xclang -ivfsoverlay -Xclang /mnt/d/Kody/C++ Projects/Test/build/winsdk_vfs_overlay.yaml  /Zi /Ob0 /Od /RTC1 -Xclang -ivfsoverlay -Xclang "/mnt/d/Kody/C++ Projects/Test/build/winsdk_vfs_overlay.yaml" -MDd /FoCMakeFiles/cmTC_4c27c.dir/testCCompiler.c.obj /FdCMakeFiles/cmTC_4c27c.dir/ -c -- "/mnt/d/Kody/C++ Projects/Test/build/CMakeFiles/CMakeScratch/TryCompile-bKMrc7/testCCompiler.c"
    clang-16: error: cannot specify '/FoCMakeFiles/cmTC_4c27c.dir/testCCompiler.c.obj' when compiling multiple source files
    make[1]: *** [CMakeFiles/cmTC_4c27c.dir/build.make:78: CMakeFiles/cmTC_4c27c.dir/testCCompiler.c.obj] Błąd 1
    make[1]: Opuszczenie katalogu '/mnt/d/Kody/C++ Projects/Test/build/CMakeFiles/CMakeScratch/TryCompile-bKMrc7'
    make: *** [Makefile:127: cmTC_4c27c/fast] Błąd 2
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:7 (project)


-- Configuring incomplete, errors occurred!

At first I thought it could be because the toolchain, splat and Geode SDK are on an NTFS partition, but I was able to compile an empty project successfully on it when the path to the project didn't contain spaces.

Also you can get xwin on Arch Linux from the AUR.

@adam11111111111111111111121

when i try to run geode on ubuntu it gives the following error:
geode: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory

@B1rtek
Copy link

B1rtek commented Feb 19, 2024

sounds like you might need to update openssl

@adam11111111111111111111121

i don't think it's that old, i run openssl version and it returns 3.1.1

@adam11111111111111111111121
Copy link

i think the issue has to do with libssl3 which is from my limited knowledge so far isn't availabe on ubuntu 20 which is my current system's version, and i found this comment # some stupid old ubuntu versions cant install libssl3
from one of geode cli repository's source files so i guess my ubuntu version is that stupid version, so i'm updating and will see what happens

update: yup, that was the issue and after the update i installed libssl3 and after that it worked

@Mawfyy
Copy link

Mawfyy commented Mar 2, 2024

One note: if the path to your Geode project contains a space, this doesn't work for some reason, failing with a following error:

-- Found SPLAT_DIR: /mnt/d/Kody/GeodeLinux/splat
-- Found HOST_ARCH: x86
-- "LLVM_VER" not set, leaving blank
-- "CLANG_VER" not set, leaving blank
-- "LLVM_PATH" not set, leaving blank
-- "LLVM_VER" not set, leaving blank
-- "CLANG_VER" not set, leaving blank
-- "LLVM_PATH" not set, leaving blank
-- The C compiler identification is Clang 16.0.6 with MSVC-like command-line
-- The CXX compiler identification is Clang 16.0.6 with MSVC-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/bin/clang-cl
-- Check for working C compiler: /usr/bin/clang-cl - broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "/usr/bin/clang-cl"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: '/mnt/d/Kody/C++ Projects/Test/build/CMakeFiles/CMakeScratch/TryCompile-bKMrc7'
    
    Run Build Command(s): /usr/bin/cmake -E env VERBOSE=1 /usr/bin/make -f Makefile cmTC_4c27c/fast
    /usr/bin/make  -f CMakeFiles/cmTC_4c27c.dir/build.make CMakeFiles/cmTC_4c27c.dir/build
    make[1]: Wejście do katalogu '/mnt/d/Kody/C++ Projects/Test/build/CMakeFiles/CMakeScratch/TryCompile-bKMrc7'
    Building C object CMakeFiles/cmTC_4c27c.dir/testCCompiler.c.obj
    /usr/bin/clang-cl  /nologo   -Xclang -fexceptions -Xclang -fcxx-exceptions -Xclang -D_CRT_SECURE_NO_WARNINGS --target=i686-windows-msvc -fms-compatibility-version=19.11 -Wno-unused-command-line-argument -imsvc /mnt/d/Kody/GeodeLinux/splat/crt/include -imsvc /mnt/d/Kody/GeodeLinux/splat/sdk/include/ucrt -imsvc /mnt/d/Kody/GeodeLinux/splat/sdk/include/shared -imsvc /mnt/d/Kody/GeodeLinux/splat/sdk/include/um -imsvc /mnt/d/Kody/GeodeLinux/splat/sdk/include/winrt -Xclang -ivfsoverlay -Xclang /mnt/d/Kody/C++ Projects/Test/build/winsdk_vfs_overlay.yaml  /Zi /Ob0 /Od /RTC1 -Xclang -ivfsoverlay -Xclang "/mnt/d/Kody/C++ Projects/Test/build/winsdk_vfs_overlay.yaml" -MDd /FoCMakeFiles/cmTC_4c27c.dir/testCCompiler.c.obj /FdCMakeFiles/cmTC_4c27c.dir/ -c -- "/mnt/d/Kody/C++ Projects/Test/build/CMakeFiles/CMakeScratch/TryCompile-bKMrc7/testCCompiler.c"
    clang-16: error: cannot specify '/FoCMakeFiles/cmTC_4c27c.dir/testCCompiler.c.obj' when compiling multiple source files
    make[1]: *** [CMakeFiles/cmTC_4c27c.dir/build.make:78: CMakeFiles/cmTC_4c27c.dir/testCCompiler.c.obj] Błąd 1
    make[1]: Opuszczenie katalogu '/mnt/d/Kody/C++ Projects/Test/build/CMakeFiles/CMakeScratch/TryCompile-bKMrc7'
    make: *** [Makefile:127: cmTC_4c27c/fast] Błąd 2
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:7 (project)


-- Configuring incomplete, errors occurred!

At first I thought it could be because the toolchain, splat and Geode SDK are on an NTFS partition, but I was able to compile an empty project successfully on it when the path to the project didn't contain spaces.

Also you can get xwin on Arch Linux from the AUR.

I have you same error without some space in the path, like this:
/home/mawfy/projects/geode_mods/hello

@AsyncTheAbyss
Copy link

AsyncTheAbyss commented Apr 29, 2024

I have you same error without some space in the path, like this: /home/mawfy/projects/geode_mods/hello
I'm also having this error, all I wanted to do was make a few changes to a mod but can't even compile any mod.
ex path with no spaces "/home/Async/Documents/gd/Testing/", spaces don't seem like they are the fix to it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment