bluepotato
Prince
- Joined
- Dec 11, 2018
- Messages
- 316
Getting the DLL to compile using wine isn't nearly as trivial as it is on Windows. But in the process of getting rid of my previous hacky Makefile setup I mostly figured this out, so I decided to write a guide for it.
Prerequisites
- A PC with a Linux distribution. I've done this on several distributions and haven't found one that this didn't work on.
- Civ 4 installed with wine. This is trivial if you have the GOG version, just winetrick msxml3 and d3dx9. See the winehq page for further information.
- Basic Linux knowledge. You should at least know stuff like how paths work and how to use wine in a terminal emulator.
Step 0: Getting the source code
You should probably have it by now, but if you don't, and want to start from scratch, clone Leoreth's repo at https://github.com/dguenms/beyond-the-sword-sdk.
Step 1: Getting wine 1.7
Why do we need such an ancient version of wine?, you might ask - and rightly so, wine 1.7 was released 5 years ago. Well as it turns out, most newer versions don't work with the VC++ 2003 compiler and will cause an internal compiler error. 1.8 or 1.9 might work as well, I just haven't tried. 2.0 definitely didn't work for me.
Luckily, PlayOnLinux provides an easy way to get wine 1.7. After installing it, go to Tools->Manage Wine Versions. Then select wine 1.7.55 (on the x86 tab), and install it. You won't need PlayOnLinux after this.
You should now be able to locate your wine executable in ~/.PlayOnLinux/wine/linux-x86/1.7.55/bin. I like to move this to a ~/.wine_versions folder so that its path is ~/.wine_versions/linux-x86/1.7.55/bin/wine.
Now create a new wineprefix using
After this, you should have a 32-bit wineprefix in the ~/compile_linux folder.
Step 2: Getting the Visual C++ 2003 Toolkit and the Platform SDK
For the VC++ 2003 Toolkit I like to use Leoreth's installer. Install this in your regular wineprefix (presumably in .wine, using your system-wide wine command), then move the .wine/drive_c/Program Files/Microsoft Visual C++ Toolkit 2003 folder to ~/compile_linux/drive_c/Program Files.
Delete the PSDK folder, it won't work. Instead, download this installer from Microsoft. Mount and install it in your regular wineprefix (next next finish, though you may want to select the Core SDK only in the custom install option). Now you should have a Program Files/Microsoft Platform SDK folder; move this to ~/compile_linux/drive_c/Program Files as well.
Step 3: Getting fastdep
You will need a fastdep binary compatible with the build script. For this you'll have to clone my patched version like this:
Place the resulting folder in your CvGameCoreDLL/bin folder, and optionally compile fastdep using make if you can't/don't want to use the binary I compiled.
Step 4: Compiling the DLL
This should be the easiest step if you've done everything correctly. I've made a shell script which functions like the Makefile (probably not perfect but it works; suggestions are welcome); just save https://raw.githubusercontent.com/bptato/RFC-Greek-World/master/CvGameCoreDLL/compile.sh in your DLL folder.
You will also have to download compile_settings.sh and save it in the same folder: https://raw.githubusercontent.com/bptato/RFC-Greek-World/master/CvGameCoreDLL/compile_settings.sh.
Then make sure the variables in compile_settings.sh match your setup. Specifically, PYTHON and BOOST should point to an existing folder; I placed these in my DLL folder, since this version of wine can behave weird with absolute paths outside of the wineprefix. If you really want to use absolute paths (to e.g. put your Python/Boost folders in your civ folder as recommended in Nightinggale's makefile thread), use something like "Z:$HOME/your/path". Also make sure the FASTDEP variable points to your fastdep binary.
Finally, make compile.sh executable:
and launch it like this:
You can also use [clean] to remove the Release/, Debug/, Final_release/, or if no target was specified, all of these folders.
And that's it!
Further notes
The final_release target (idea from advciv's makefile) performs whole program optimization. This means that linking takes ages, but you supposedly get a somewhat faster DLL.
Also, by default, the script will spawn a child process for checking and compiling every single cpp file to make use of all available processing power. While this speeds up compilation on my (hexa-core) system, it may actually be slower than running a single process on systems with a low amount of cores. Change PARALLEL=true to PARALLEL=false in compile_settings.sh to disable this.
For editing the sources, any text editor works. Those that I've found so far with somewhat usable code completion support are Geany, and vim/neovim with the OmniCppComplete plugin. CodeBlocks's completion also works nicely, but it's a huge pain to set up (an ancient windows version is required, which of course can't use compile.sh). And I haven't the slightest clue how to get the clangd language server to cooperate, unfortunately.
Debugging can be done with winedbg, see this page for further information. Most of the time you'll want to use the info proc (get civ 4's process id), attach (attach to a running instance of civ 4), cont (after attaching) and bt (get backtrace) commands.
Prerequisites
- A PC with a Linux distribution. I've done this on several distributions and haven't found one that this didn't work on.
- Civ 4 installed with wine. This is trivial if you have the GOG version, just winetrick msxml3 and d3dx9. See the winehq page for further information.
- Basic Linux knowledge. You should at least know stuff like how paths work and how to use wine in a terminal emulator.
Step 0: Getting the source code
You should probably have it by now, but if you don't, and want to start from scratch, clone Leoreth's repo at https://github.com/dguenms/beyond-the-sword-sdk.
Step 1: Getting wine 1.7
Why do we need such an ancient version of wine?, you might ask - and rightly so, wine 1.7 was released 5 years ago. Well as it turns out, most newer versions don't work with the VC++ 2003 compiler and will cause an internal compiler error. 1.8 or 1.9 might work as well, I just haven't tried. 2.0 definitely didn't work for me.
Luckily, PlayOnLinux provides an easy way to get wine 1.7. After installing it, go to Tools->Manage Wine Versions. Then select wine 1.7.55 (on the x86 tab), and install it. You won't need PlayOnLinux after this.
You should now be able to locate your wine executable in ~/.PlayOnLinux/wine/linux-x86/1.7.55/bin. I like to move this to a ~/.wine_versions folder so that its path is ~/.wine_versions/linux-x86/1.7.55/bin/wine.
Now create a new wineprefix using
Code:
$ export WINEPREFIX=~/compile_linux; ~/.wine_versions/linux-x86/1.7.55/bin/wine wineboot
Step 2: Getting the Visual C++ 2003 Toolkit and the Platform SDK
For the VC++ 2003 Toolkit I like to use Leoreth's installer. Install this in your regular wineprefix (presumably in .wine, using your system-wide wine command), then move the .wine/drive_c/Program Files/Microsoft Visual C++ Toolkit 2003 folder to ~/compile_linux/drive_c/Program Files.
Delete the PSDK folder, it won't work. Instead, download this installer from Microsoft. Mount and install it in your regular wineprefix (next next finish, though you may want to select the Core SDK only in the custom install option). Now you should have a Program Files/Microsoft Platform SDK folder; move this to ~/compile_linux/drive_c/Program Files as well.
Step 3: Getting fastdep
You will need a fastdep binary compatible with the build script. For this you'll have to clone my patched version like this:
Code:
$ svn checkout https://github.com/bptato/RFC-Greek-World/trunk/CvGameCoreDLL/bin/fastdep-0.16
Step 4: Compiling the DLL
This should be the easiest step if you've done everything correctly. I've made a shell script which functions like the Makefile (probably not perfect but it works; suggestions are welcome); just save https://raw.githubusercontent.com/bptato/RFC-Greek-World/master/CvGameCoreDLL/compile.sh in your DLL folder.
You will also have to download compile_settings.sh and save it in the same folder: https://raw.githubusercontent.com/bptato/RFC-Greek-World/master/CvGameCoreDLL/compile_settings.sh.
Then make sure the variables in compile_settings.sh match your setup. Specifically, PYTHON and BOOST should point to an existing folder; I placed these in my DLL folder, since this version of wine can behave weird with absolute paths outside of the wineprefix. If you really want to use absolute paths (to e.g. put your Python/Boost folders in your civ folder as recommended in Nightinggale's makefile thread), use something like "Z:$HOME/your/path". Also make sure the FASTDEP variable points to your fastdep binary.
Finally, make compile.sh executable:
Code:
$ chmod +x compile.sh
Code:
$ ./compile.sh [release/debug/final_release]
And that's it!
Further notes
The final_release target (idea from advciv's makefile) performs whole program optimization. This means that linking takes ages, but you supposedly get a somewhat faster DLL.
Also, by default, the script will spawn a child process for checking and compiling every single cpp file to make use of all available processing power. While this speeds up compilation on my (hexa-core) system, it may actually be slower than running a single process on systems with a low amount of cores. Change PARALLEL=true to PARALLEL=false in compile_settings.sh to disable this.
For editing the sources, any text editor works. Those that I've found so far with somewhat usable code completion support are Geany, and vim/neovim with the OmniCppComplete plugin. CodeBlocks's completion also works nicely, but it's a huge pain to set up (an ancient windows version is required, which of course can't use compile.sh). And I haven't the slightest clue how to get the clangd language server to cooperate, unfortunately.
Debugging can be done with winedbg, see this page for further information. Most of the time you'll want to use the info proc (get civ 4's process id), attach (attach to a running instance of civ 4), cont (after attaching) and bt (get backtrace) commands.
Last edited: