TurningWheel / Barony

Barony Open Source Release
http://www.baronygame.com/
Other
487 stars 126 forks source link

Building on Windows 10 #98

Closed crkellen closed 7 years ago

crkellen commented 7 years ago

Hello,

I'd really like to start working on this, and I'd like to build it on Windows if at all possible. However, if absolutely necessary, I can attempt to build it on Linux.

I'm having issues with the first library, libpng, as it has no Windows build. I was told that it is possible to build it on Windows, but how exactly is this done? Do I have to build libpng for Windows?

Are there any guides or information for building this project? I don't have a ton of experience building a project like this.

Thanks.

SheridanR commented 7 years ago

Yes, after a glance at libpng it looks like it will have to be built for windows. In general, since you seem to be new to the idea of building the libraries you need, generally you will find that's not too unusual. It can be a hassle, but as a matter of principle, it also has important upsides. It means you can build a copy for your particular arch and OS, you can build with varying levels of debug info, and you can choose what features to compile the library with. Many support libraries such as this one, zlib, openssl, etc. have flags that can be toggled on and off to activate / deactivate features of the library. But this is all high level stuff.

When you find that you need to build a portable system level library, the first thing you should always look for is the INSTALL file. Sometimes this file is named other things, or embedded in the README. But the important thing is that this file contains build instructions. Now in the case of libpng, I can also see that it has a CMakeFiles.txt in the source archive. This likely means that the lib can be built with CMake, which is (usually) easy to setup.

In short: if you wanna build libpng, read the INSTALL, and (probably) download cmake and run it in the source archive. This will give you a visual studio sln you can open, hit "Build Solution" and get the libs / dlls you need.

crkellen commented 7 years ago

I currently have Cygwin installed, and I often see that as the recommended alternative, should I/could I use that? I only ask because I often see that Cmake is not possible sometimes? I may be completely wrong. I'll go grab it and give it a shot. Thanks!

SheridanR commented 7 years ago

CMake isn't a shell, it's a build configuration system.

crkellen commented 7 years ago

Yeah, I see that now. Looking for how exactly to build it now. Do I need to build zlib with it? I seem to only find tutorials for building zlib AND libpng.

EDIT: Oh man im dumb, I was reading the install file and seemed to completely miss the section that said "Before installing libpng, you must first install zlib"

SheridanR commented 7 years ago

Yeah, zlib is much the same as libpng, so with any luck, both will go smoothly for you :)

crkellen commented 7 years ago

I am attempting it now, to what I believe is some degree of success. Cmake worked fine, but I can't actually use "make" so I tried nmake, but that didn't work, so now I'm following a video and we'll see where that goes. If I encounter any issues, I'll post here. null

SheridanR commented 7 years ago

If you intend to build the game using visual studio you need to build the libraries with visual studio as well. Make sure to specify the correct generator to CMake to produce project files for your version of Visual Studio or you'll end up with makefiles for some other compiler instead.

SheridanR commented 7 years ago

The command you're looking for is something like this: cmake -G "Visual Studio 2015 13"

crkellen commented 7 years ago

Thanks!Like I said, new to this whole building process. Learning a lot though! null

crkellen commented 7 years ago

I attempted that, cmd opened in the zlib folder, then typing cmake -G "Visual Studio 15 2017

But that doesn't work, because there is no 64bit option, and that's the only way it will do it, so I tried cmake -G "Visual Studio 15 2017 ARM and that doesn't work either, so I am continuing to follow this tutorial: https://www.youtube.com/watch?v=GsgSnSG0O0U

But mind you, I'm using Visual Studio 2017, which when getting to the part where I open the solution, it tells me I can upgrade the target (140 to 141). I try not to, doesn't work, because apparently I dont have that installed. Maybe I can install it. I tried retargeting it to 141, and it says zconf.h is missing. Googling around, and I'm guessing I'm just going to need to download Visual Studio 2015, or this 140 target thing.

EDIT: Just finishing up the download for VS2015. I'll see how it goes.

crkellen commented 7 years ago

EDIT: After giving it a fresh run, and using some new knowledge, I believe I correctly and fully built zlib using CMake. I attempted to build libpng, but I was only able to create the project files. The command cmake --build . fails due to zlib.h missing. Realizing I probably need to copy over zlib.h from the built files, I realize it's not in the built files. However, I can find a zlib.h in the downloaded .zip file, so I dropped that in the project directory.

I also know that it will complain about zconf.h, so I take that from the built zlib files and drop it in the directory as well. I run the --build command again and now I have 17 errors:

"C:\BARONYLIBS\LIBPNG\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\BARONYLIBS\LIBPNG\png.vcxproj" (default target) (3) ->
(Link target) ->
  png.obj : error LNK2019: unresolved external symbol inflateReset referenced in function png_reset_zstream [C:\BARONYLIBS\LIBPNG\png.vcxproj]
  pngrutil.obj : error LNK2001: unresolved external symbol inflateReset [C:\BARONYLIBS\LIBPNG\png.vcxproj]
  png.obj : error LNK2019: unresolved external symbol adler32 referenced in function png_compare_ICC_profile_with_sRGB [C:\BARONYLIBS\LIBPNG\png.vcxproj]
  png.obj : error LNK2019: unresolved external symbol crc32 referenced in function png_reset_crc [C:\BARONYLIBS\LIBPNG\png.vcxproj]
  pngread.obj : error LNK2019: unresolved external symbol inflateEnd referenced in function png_read_destroy [C:\BARONYLIBS\LIBPNG\png.vcxproj]
  pngrutil.obj : error LNK2019: unresolved external symbol inflate referenced in function png_zlib_inflate [C:\BARONYLIBS\LIBPNG\png.vcxproj]
  pngrutil.obj : error LNK2019: unresolved external symbol inflateReset2 referenced in function png_inflate_claim [C:\BARONYLIBS\LIBPNG\png.vcxproj]
  pngrutil.obj : error LNK2019: unresolved external symbol inflateInit2_ referenced in function png_inflate_claim [C:\BARONYLIBS\LIBPNG\png.vcxproj]
  pngrutil.obj : error LNK2019: unresolved external symbol inflateValidate referenced in function png_inflate_claim [C:\BARONYLIBS\LIBPNG\png.vcxproj]
  pngwrite.obj : error LNK2019: unresolved external symbol deflateEnd referenced in function png_write_destroy [C:\BARONYLIBS\LIBPNG\png.vcxproj]
  pngwutil.obj : error LNK2001: unresolved external symbol deflateEnd [C:\BARONYLIBS\LIBPNG\png.vcxproj]
  pngwutil.obj : error LNK2019: unresolved external symbol deflate referenced in function png_compress_IDAT [C:\BARONYLIBS\LIBPNG\png.vcxproj]
  pngwutil.obj : error LNK2019: unresolved external symbol deflateReset referenced in function png_deflate_claim [C:\BARONYLIBS\LIBPNG\png.vcxproj]
  pngwutil.obj : error LNK2019: unresolved external symbol deflateInit2_ referenced in function png_deflate_claim [C:\BARONYLIBS\LIBPNG\png.vcxproj]
  C:\BARONYLIBS\LIBPNG\Debug\libpng16d.dll : fatal error LNK1120: 12 unresolved externals [C:\BARONYLIBS\LIBPNG\png.vcxproj]

"C:\BARONYLIBS\LIBPNG\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\BARONYLIBS\LIBPNG\png-fix-itxt.vcxproj" (default target) (5) ->
  png-fix-itxt.obj : error LNK2019: unresolved external symbol crc32 referenced in function main [C:\BARONYLIBS\LIBPNG\png-fix-itxt.vcxproj]
  C:\BARONYLIBS\LIBPNG\Debug\png-fix-itxt.exe : fatal error LNK1120: 1 unresolved externals [C:\BARONYLIBS\LIBPNG\png-fix-itxt.vcxproj]

This is as far as I have been able to make it. I made it to this point earlier in my journey as well. If it matters, this is my steps to get to this point:

  1. Create a new directory CL\BARONYLIBS\ZLIB and open CMD there.
  2. run cmake -G "Visual Studio 15 2017" -A x64 C:\BARONYLIBS\zlib-1.2.11
  3. run cmake --build .
  4. Create a new directory C:\BARONYLIBS\LIBPNG and open CMD there.
  5. run cmake -G "Visual Studio 15 2017" -A x64 C:\BARONYLIBS\lpng1630
  6. Take a copy of zlib.h from C:\BARONYLIBS\zlib-1.2.11 and place it in C:\BARONYLIBS\LIBPNG
  7. Take a copy of zconf.h from C:\BARONYLIBS\ZLIB and place it in C:\BARONYLIBS\LIBPNG
  8. run cmake --build .

Any ideas?


OUTDATED INFO:

From the current looks of things, I highly doubt I will be able to get this to work effectively. There seems to be major issues with compiling to a Win32 project. I suppose I could attempt to build it 64bit, which I'm assuming would require me to somehow rework the barony source to be 64bit?

At this point, I'm up to do whatever needs to be done to start actually building Barony and working on it. Since there is no tutorial/instructions other than the simplistic INSTALL.txt, any help would be appreciated.

If at all possible, I would love to find some sort of way to:

  1. Build zlib using Visual Studio 2017 (which happens to use v141, which to my knowledge is just the Visual Studio 15 compiler, but 64bit only?).

  2. Build libpng using Visual Studio 2017.

  3. Build all of the SDL requirements using Visual Studio 2017. (I believe I have actually already done this, so that shouldn't be an issue at all).

  4. Build Barony using Visual Studio 2017.

My install of Visual Studio 2015 seems to be broken in some way or another (something about every single required add-on being completely and totally broken), but the compiler seems to work fine through Visual Studio 2017 (as in, I can set the build target to v140 and it doesn't complain about v140 not being installed). I fixed the installation by using the Repair.

If I can't get this to work as a 32bit build, I'm willing to figure out how to do it as a 64bit build. I have zero experience in converting/building a project/library into 64bit and honestly have zero idea what that even changes other than memory addresses. However, I have a willingness to learn and experiment if someone is willing to lend a hand.

If absolutely all else fails, I have a terrible Oracle VM VirtualBox running Unbuntu that I could use to attempt to build this. It is however likely that something is broken with that as well, as I distinctly remember having issues installing Visual Studio Code (wont open at all), and issues with the download manager application thing.

Help, Advice, Tutorials, or anything else is appreciated.

crkellen commented 7 years ago

I believe I have successfully built both zlib and libpng for Debug. I could probably easily do it for Release, but I'm posting this now.

Only issue, they are currently built using x64, not x86. I'm not sure if this will conflict with Barony. How exactly am I supposed to be linking these to the Barony project? Am I linking the built "Debug" folder, or am I copying a file or more to the barony directory?

Thanks for any help you can provide.

EDIT: I just built it for Release as well.

crkellen commented 7 years ago

EDIT: Now all I'm missing is 'dirent.h' Not sure where to find that one. Found a windows version of it.


EDIT: I swapped the line #include <GL/glext.h> to #include "SDL_opengl_glext.h" and that worked. Now it is complaining about fmod.h missing, but I have no idea what that is, or where I would find it. It's not in any of my folders. I'm dumb. I forgot I didn't download Fmod yet. Doing that now.

Attempted to build the project after what I believe is correcting linking all includes/libs.

However, I have a strange issue. 'GL/glext.h' cannot be found. I get that spammed over and over from main.hpp, and I get few other issues. The other issues I get are: Cannot open include file "png.h" Cannot open include file "dirent.h"

Any idea where this glext.h is supposed to come from? Only thing i can see referencing that name is "SDL_opengl_glext.h" is this the file I am looking for?

SheridanR commented 7 years ago

glext.h isn't included with some compilers for some unknown reason. You can find it online and just download it to your include path and then the game should build.

crkellen commented 7 years ago

Okay, I think I'm very close because I'm at the linking stage.

I have 253 errors, most of them are something along the lines of: LNK2019 unresolved external symbol _SDL_GetError or some other SDL function. Not sure what I'm missing exactly, so I'm going to keep at it.


As I was typing you responded. Okay, I'll download glext.h and include it.

SheridanR commented 7 years ago

You also need png.h in your include path as well as dirent.h. The latter is a POSIX header, you can also find windows ports of it online (again, simply download to the include path). png.h is in the libpng source archive you downloaded. Pull it out of there and stick it in your include path to build.

SheridanR commented 7 years ago

Remember that the INSTALL for our project mentioned you will need to customize the library and include paths in the barony and editor project to build the game. You'll run into linking and compile errors until you get those things sorted out.

crkellen commented 7 years ago

Yeah, I read that and did include those things as needed. I also had to build with Cmake to get the FMOD flag set to false.

I did place in all of the png headers I needed, there was about 4 of them. I also downloaded and added dirent.h. I just downloaded and added in glext.h (so now the line reads #include "glext.h"). I just built and I still have the 253 errors, so I'm going to have to find out what I'm missing in my linker.

EDIT: When I rebuilt it using Cmake, I accidentally linked the /lib folders, not the /lib/x86 folders. Fixing that now.

crkellen commented 7 years ago

EDIT 2: It seems the issue is the fact that I built libpng and zlib x64 not x86. I'll have to go back and see if I can figure out how to compile zlib x86. The reason I did x64 was because I was finding it impossible to do x86.

I'm down to just 12 unresolved external symbols. However, I'm having trouble figuring out what it wants me to link. Do you have any idea?

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol _png_create_write_struct referenced in function "int __cdecl SDL_SavePNG_RW(struct SDL_Surface *,struct SDL_RWops *,int)" (?SDL_SavePNG_RW@@YAHPAUSDL_Surface@@PAUSDL_RWops@@H@Z)    barony  C:\Users\DrWhoCares\Documents\CODING\GIT\Barony\BUILD\savepng.obj   1   
Error   LNK2019 unresolved external symbol _png_set_longjmp_fn referenced in function "int __cdecl SDL_SavePNG_RW(struct SDL_Surface *,struct SDL_RWops *,int)" (?SDL_SavePNG_RW@@YAHPAUSDL_Surface@@PAUSDL_RWops@@H@Z) barony  C:\Users\DrWhoCares\Documents\CODING\GIT\Barony\BUILD\savepng.obj   1   
Error   LNK2019 unresolved external symbol _png_create_info_struct referenced in function "int __cdecl SDL_SavePNG_RW(struct SDL_Surface *,struct SDL_RWops *,int)" (?SDL_SavePNG_RW@@YAHPAUSDL_Surface@@PAUSDL_RWops@@H@Z) barony  C:\Users\DrWhoCares\Documents\CODING\GIT\Barony\BUILD\savepng.obj   1   
Error   LNK2019 unresolved external symbol _png_write_info referenced in function "int __cdecl SDL_SavePNG_RW(struct SDL_Surface *,struct SDL_RWops *,int)" (?SDL_SavePNG_RW@@YAHPAUSDL_Surface@@PAUSDL_RWops@@H@Z) barony  C:\Users\DrWhoCares\Documents\CODING\GIT\Barony\BUILD\savepng.obj   1   
Error   LNK2019 unresolved external symbol _png_set_bgr referenced in function "int __cdecl SDL_SavePNG_RW(struct SDL_Surface *,struct SDL_RWops *,int)" (?SDL_SavePNG_RW@@YAHPAUSDL_Surface@@PAUSDL_RWops@@H@Z)    barony  C:\Users\DrWhoCares\Documents\CODING\GIT\Barony\BUILD\savepng.obj   1   
Error   LNK2019 unresolved external symbol _png_write_image referenced in function "int __cdecl SDL_SavePNG_RW(struct SDL_Surface *,struct SDL_RWops *,int)" (?SDL_SavePNG_RW@@YAHPAUSDL_Surface@@PAUSDL_RWops@@H@Z)    barony  C:\Users\DrWhoCares\Documents\CODING\GIT\Barony\BUILD\savepng.obj   1   
Error   LNK2019 unresolved external symbol _png_write_end referenced in function "int __cdecl SDL_SavePNG_RW(struct SDL_Surface *,struct SDL_RWops *,int)" (?SDL_SavePNG_RW@@YAHPAUSDL_Surface@@PAUSDL_RWops@@H@Z)  barony  C:\Users\DrWhoCares\Documents\CODING\GIT\Barony\BUILD\savepng.obj   1   
Error   LNK2019 unresolved external symbol _png_destroy_write_struct referenced in function "int __cdecl SDL_SavePNG_RW(struct SDL_Surface *,struct SDL_RWops *,int)" (?SDL_SavePNG_RW@@YAHPAUSDL_Surface@@PAUSDL_RWops@@H@Z)   barony  C:\Users\DrWhoCares\Documents\CODING\GIT\Barony\BUILD\savepng.obj   1   
Error   LNK2019 unresolved external symbol _png_set_write_fn referenced in function "int __cdecl SDL_SavePNG_RW(struct SDL_Surface *,struct SDL_RWops *,int)" (?SDL_SavePNG_RW@@YAHPAUSDL_Surface@@PAUSDL_RWops@@H@Z)   barony  C:\Users\DrWhoCares\Documents\CODING\GIT\Barony\BUILD\savepng.obj   1   
Error   LNK2019 unresolved external symbol _png_get_io_ptr referenced in function "void __cdecl png_write_SDL(struct png_struct_def *,unsigned char *,unsigned int)" (?png_write_SDL@@YAXPAUpng_struct_def@@PAEI@Z) barony  C:\Users\DrWhoCares\Documents\CODING\GIT\Barony\BUILD\savepng.obj   1   
Error   LNK2019 unresolved external symbol _png_set_IHDR referenced in function "int __cdecl SDL_SavePNG_RW(struct SDL_Surface *,struct SDL_RWops *,int)" (?SDL_SavePNG_RW@@YAHPAUSDL_Surface@@PAUSDL_RWops@@H@Z)   barony  C:\Users\DrWhoCares\Documents\CODING\GIT\Barony\BUILD\savepng.obj   1   
Error   LNK2019 unresolved external symbol _png_set_PLTE referenced in function "int __cdecl SDL_SavePNG_RW(struct SDL_Surface *,struct SDL_RWops *,int)" (?SDL_SavePNG_RW@@YAHPAUSDL_Surface@@PAUSDL_RWops@@H@Z)   barony  C:\Users\DrWhoCares\Documents\CODING\GIT\Barony\BUILD\savepng.obj   1   

EDIT: Apparently it wants me to link libpng.lib, but that file doesn't exist. I have already linked libpng16_staticd.lib and libpng16d.lib before I had this issue, but that seems to not be the same as "libpng.lib"

crkellen commented 7 years ago

I successfully built and ran Barony

I built zlib 32bit I built libpng 32bit I linked the new libpng and zlib to my build of Barony without FMOD I built it, and dropped the .exe in the Steam common folder. I dropped zlibd.dll into the Steam common folder. I ran the game successfully.


So, I'm seemingly ready to start delving into the code rather than the dungeons, going to build zlib/libpng as Release now, and link that to Barony Release, and see if I can get FMOD to work as well, since FMOD support let me download it. After that, no clue, such a large code base, I don't really know where to start, so I guess I'll start small and see what happens. Thanks a ton for your help @SheridanR ! I'll leave this open in case anything goes wrong, or I can't get FMOD to work, I'll close it if I get everything linked and built correctly!

WALLOFJUSTICE commented 7 years ago

Glad to hear you got it working! FMOD should be no problem if you got this far. If you need any help with the code, feel free to join the Barony community Discord and message myself https://discord.gg/eQrg3HV

crkellen commented 7 years ago

Thanks! I didn't know there was a discord, I'll be on in around 3-4 hours! null

SheridanR commented 7 years ago

I recommend against dropping the binary in your steam folder because you won't be able to use features of Steam such as matchmaking.

Also, don't even bother trying to build the game with FMOD. Download OpenAL and build the game with that instead.

crkellen commented 7 years ago

Oh? The reason I dropped it in there is because I remember reading somewhere, you wrote that the easiest way to play was to drop the built .exe into the Steam folder, because you still need to own the game files to play.

Do I need to rebuild Barony using Cmake with the OpenAL flag set then, or is the default project assuming OpenAL?

SheridanR commented 7 years ago

You do need the game files to play, but I recommend building your own game directory outside of steam by copying all the game assets from Steam to a new folder. Otherwise your .exe will be overwritten when Barony updates on Steam and, as mentioned, you won't have access to steamworks features.

The default project assumes FMOD, but that is due to be deprecated. FMOD is a closed-source sound library with limited access (you need to create an online account to even download it). It was a mistake to use it in the first place. We are already using OpenAL for our next project, and I was impressed that a couple contributors pulled together really quickly and implemented OpenAL support into Barony as well.

crkellen commented 7 years ago

Okay, I will attempt to get OpenAL to work. To circumvent any .exe overwriting issues, I actually have three .exe's in the steam folder: baronySTABLE.exe (the steam version) baronyDEBUG.exe (built debug version) baronyRELEASE.exe (built release version)

I'll rework everything and see what I can do. Once again, if I get it building with OpenAL, and also get it running in a separate folder and such, I will close this. Thanks!

crkellen commented 7 years ago

Attempting to build with OpenAL. I have OpenAL32.lib linked, and there isn't any other .lib files for OpenAL other than the EXF-Util files, which I tried linking (did nothing). What am I missing here?

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol _ov_clear referenced in function "int __cdecl OPENAL_CreateSound(char const *,bool,struct OPENAL_BUFFER * *)" (?OPENAL_CreateSound@@YAHPBD_NPAPAUOPENAL_BUFFER@@@Z)  barony  C:\BARONYBUILD\Barony\VS.2015\Barony\sound.obj  1   
Error   LNK2019 unresolved external symbol _ov_open referenced in function "int __cdecl OPENAL_CreateSound(char const *,bool,struct OPENAL_BUFFER * *)" (?OPENAL_CreateSound@@YAHPBD_NPAPAUOPENAL_BUFFER@@@Z)   barony  C:\BARONYBUILD\Barony\VS.2015\Barony\sound.obj  1   
Error   LNK2019 unresolved external symbol _ov_open_callbacks referenced in function "int __cdecl openal_oggopen(struct OPENAL_SOUND *,char const *)" (?openal_oggopen@@YAHPAUOPENAL_SOUND@@PBD@Z)  barony  C:\BARONYBUILD\Barony\VS.2015\Barony\sound.obj  1   
Error   LNK2019 unresolved external symbol _ov_pcm_total referenced in function "int __cdecl OPENAL_CreateSound(char const *,bool,struct OPENAL_BUFFER * *)" (?OPENAL_CreateSound@@YAHPBD_NPAPAUOPENAL_BUFFER@@@Z)  barony  C:\BARONYBUILD\Barony\VS.2015\Barony\sound.obj  1   
Error   LNK2019 unresolved external symbol _ov_raw_seek referenced in function "int __cdecl openal_oggrelease(struct OPENAL_SOUND *)" (?openal_oggrelease@@YAHPAUOPENAL_SOUND@@@Z)  barony  C:\BARONYBUILD\Barony\VS.2015\Barony\sound.obj  1   
Error   LNK2019 unresolved external symbol _ov_pcm_seek referenced in function "int __cdecl OPENAL_CreateSound(char const *,bool,struct OPENAL_BUFFER * *)" (?OPENAL_CreateSound@@YAHPBD_NPAPAUOPENAL_BUFFER@@@Z)   barony  C:\BARONYBUILD\Barony\VS.2015\Barony\sound.obj  1   
Error   LNK2019 unresolved external symbol _ov_info referenced in function "int __cdecl OPENAL_CreateSound(char const *,bool,struct OPENAL_BUFFER * *)" (?OPENAL_CreateSound@@YAHPBD_NPAPAUOPENAL_BUFFER@@@Z)   barony  C:\BARONYBUILD\Barony\VS.2015\Barony\sound.obj  1   
Error   LNK2019 unresolved external symbol _ov_comment referenced in function "int __cdecl openal_oggopen(struct OPENAL_SOUND *,char const *)" (?openal_oggopen@@YAHPAUOPENAL_SOUND@@PBD@Z) barony  C:\BARONYBUILD\Barony\VS.2015\Barony\sound.obj  1   
Error   LNK2019 unresolved external symbol _ov_read referenced in function "int __cdecl OPENAL_CreateSound(char const *,bool,struct OPENAL_BUFFER * *)" (?OPENAL_CreateSound@@YAHPBD_NPAPAUOPENAL_BUFFER@@@Z)   barony  C:\BARONYBUILD\Barony\VS.2015\Barony\sound.obj  1   
crkellen commented 7 years ago

I have successfully built Barony using OpenAL. Sounds work. I'll write a guide or something on how to build Barony for windows later.