OpenXcom Forum

Contributions => Programming => Topic started by: Bubuskac on February 04, 2018, 01:41:16 am

Title: Build on Windows without VS
Post by: Bubuskac on February 04, 2018, 01:41:16 am
Hi Everyone!

I'm trying to build a version of my own, but first I try to build the source without any change. I managed to build all the dependencies (or download them), but they seems to be broken. I am able to start my build, but I cannot start a new game, because it crashes or freeze or simply exits depending the dlls I put in the path. I have several questions:
 - how can I figure out which dll to use, or which version of the dependencies are the good ones to build from?
 - SupSuper's nightly build does not require any dlls, how could I achieve that? The nightly is a bit smaller than my build.
 - I build with mingw32-make (MSYS), because that what I know is free. Is there a free version of Visual Studio? Should I use it?

Thank you!
Title: Re: Build on Windows without VS
Post by: Meridian on February 04, 2018, 01:51:54 am
- how can I figure out which dll to use, or which version of the dependencies are the good ones to build from?

You can use SupSuper's pre-compiled dependencies for VS2010 and VS2013.
For VS2015 and VS2017, you can use my pre-compiled dependencies if you want: https://openxcom.org/forum/index.php/topic,3937.msg80377.html#msg80377

If you want to use something else, you will need to compile them yourself.

- SupSuper's nightly build does not require any dlls, how could I achieve that? The nightly is a bit smaller than my build.

You can achieve that by linking the libraries statically, not dynamically.

- I build with mingw32-make (MSYS), because that what I know is free. Is there a free version of Visual Studio? Should I use it?

Yes, both VS2015 Community Edition and VS2017 Community Edition are free... you can use them.
Title: Re: Build on Windows without VS
Post by: Bubuskac on February 04, 2018, 02:26:33 am
Ok, thanks, I'll try visual studio tomorrow.
Title: Re: Build on Windows without VS
Post by: Bubuskac on February 04, 2018, 02:39:42 pm
I download VS2017 and a tried the build. I set the include and lib path, and I have 4 unresolved external symbols.

With DLL linking there is only one.

Severity   Code   Description   Project   File   Line   Suppression State
Error   LNK2001   unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > YAML::detail::node_data::empty_scalar" (?empty_scalar@node_data@detail@YAML@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A)   OpenXcom   C:\Users\aron116\Downloads\OpenXcom-master\OpenXcom-master\src\AIModule.obj   1   

This is for both.

Severity   Code   Description   Project   File   Line   Suppression State
Error   LNK2001   unresolved external symbol __imp__freopen   OpenXcom   C:\Users\aron116\Downloads\OpenXcom-master\OpenXcom-master\src\SDLmain.lib(SDL_win32_main.obj)   1   
Severity   Code   Description   Project   File   Line   Suppression State
Error   LNK2001   unresolved external symbol __imp__remove   OpenXcom   C:\Users\aron116\Downloads\OpenXcom-master\OpenXcom-master\src\SDLmain.lib(SDL_win32_main.obj)   1   
Severity   Code   Description   Project   File   Line   Suppression State
Error   LNK2001   unresolved external symbol __imp__setbuf   OpenXcom   C:\Users\aron116\Downloads\OpenXcom-master\OpenXcom-master\src\SDLmain.lib(SDL_win32_main.obj)   1   

These are for static linking. Am I missing something? Is it hard to build these libs? Shall I give it a try?
Title: Re: Build on Windows without VS
Post by: Meridian on February 04, 2018, 04:14:40 pm
With DLL linking there is only one.

Severity   Code   Description   Project   File   Line   Suppression State
Error   LNK2001   unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > YAML::detail::node_data::empty_scalar" (?empty_scalar@node_data@detail@YAML@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A)   OpenXcom   C:\Users\aron116\Downloads\OpenXcom-master\OpenXcom-master\src\AIModule.obj   1   

Did you put YAML_CPP_DLL in the pre-processor directives as mentioned here: https://openxcom.org/forum/index.php/topic,3937.msg80377.html#msg80377 ?
Title: Re: Build on Windows without VS
Post by: Bubuskac on February 04, 2018, 05:16:12 pm
No...

But the other three still a problem. I switch back to Multi threaded DLL /MD from /MT, so hopefully it will build now. Any other way to do static linking? Sorry for the noob questions, but I didn't touch c/c++ code since university, so I am a noob in this. :)
Title: Re: Build on Windows without VS
Post by: Meridian on February 04, 2018, 05:27:21 pm
Sorry for the noob questions, but I didn't touch c/c++ code since university, so I am a noob in this. :)

Same here :)
I'll let someone more competent answer the question about static/dynamic linking...
Title: Re: Build on Windows without VS
Post by: Bubuskac on February 04, 2018, 06:35:48 pm
Thanks for your help! It works! Compiled, built and runs as expected.
So now I can focus on enhancing my idea. :D
Title: Re: Build on Windows without VS
Post by: Meridian on February 04, 2018, 06:39:14 pm
Please do share your ideas with the community too... it's beneficial to everyone :)
Title: Re: Build on Windows without VS
Post by: Bubuskac on February 08, 2018, 02:57:57 pm
It's not a "new" idea, it's rather backporting one from the newest XCOM. :) Basically use fixed characters instead of random.
Title: Re: Build on Windows without VS
Post by: BTAxis on August 19, 2018, 03:02:46 pm
To stay on topic, I have in fact succeeded in building on Windows without VS. For this I used msys2/MinGW-w64.

I did have to edit some files to get it to work:

- src/Makefile.gcc-pch
On line 25, change
Code: [Select]
CXXFLAGS ?= -Wall -Wextra -Wno-unused-function -O2 -rdynamic -g -D_DEBUGto
Code: [Select]
CXXFLAGS ?= -Wall -Wextra -Wno-unused-function -O2 -g -D_DEBUGThe -rdynamic flag apparently doesn't exist in MinGW (https://stackoverflow.com/questions/17483306/compiling-with-mingw-unrecognized-command-line-option).

On line 30, change
Code: [Select]
LIBS = $(shell $(PKG-CONFIG) --libs sdl yaml-cpp) -lSDL_gfx -lSDL_mixer -lSDL_image -lGLto
Code: [Select]
LIBS = $(shell $(PKG-CONFIG) --libs sdl yaml-cpp) -lSDL_gfx -lSDL_mixer -lSDL_image -lopengl32 -lshlwapi
- src/Engine/Zoom.cpp
Find the following lines
Code: [Select]
#ifdef __GNUC__
#if (__i386__ || __x86_64__)
#include <cpuid.h>
#endif
#endif
and delete them. I built using the x86_64 toolchain, which causes a problem with this. Chalk it up to A Windows Thing.

To build, go into src/ and invoke
Code: [Select]
make -f Makefile.gcc-pch

Unfortunately, this process does not at this time seem to work for OpenXComExtended+. When linking it errors out with
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../obj/linux/WarningMessage.o: in function `OpenXcom::WarningMessage::WarningMessage(int, int, int, int)':
d:\Games\OpenXCOM\OXCE+\src/Battlescape/WarningMessage.cpp:41: undefined reference to `OpenXcom::Text::setWordWrap(bool, bool)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../obj/linux/CannotReequipState.o: in function `OpenXcom::CannotReequipState::CannotReequipState(std::vector<OpenXcom::ReequipStat, std::allocator<OpenXcom::ReequipStat> >)':
d:\Games\OpenXCOM\OXCE+\src/Battlescape/CannotReequipState.cpp:73: undefined reference to `OpenXcom::Text::setWordWrap(bool, bool)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../obj/linux/InfoboxState.o: in function `OpenXcom::InfoboxState::InfoboxState(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)':
d:\Games\OpenXCOM\OXCE+\src/Battlescape/InfoboxState.cpp:58: undefined reference to `OpenXcom::Text::setWordWrap(bool, bool)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../obj/linux/AliensCrashState.o: in function `OpenXcom::AliensCrashState::AliensCrashState()':
d:\Games\OpenXCOM\OXCE+\src/Battlescape/AliensCrashState.cpp:67: undefined reference to `OpenXcom::Text::setWordWrap(bool, bool)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../obj/linux/InfoboxOKState.o: in function `OpenXcom::InfoboxOKState::InfoboxOKState(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)':
d:\Games\OpenXCOM\OXCE+\src/Battlescape/InfoboxOKState.cpp:70: undefined reference to `OpenXcom::Text::setWordWrap(bool, bool)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../obj/linux/BuildNewBaseState.o:d:\Games\OpenXCOM\OXCE+\src/Geoscape/BuildNewBaseState.cpp:136: more undefined references to `OpenXcom::Text::setWordWrap(bool, bool)' follow
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile.gcc-pch:42: ../bin/openxcom] Error 1
It seems the function declaration of setWordWrap has changed to accept a third argument, which VC apparently accepts but g++ does not.

Edit: I tried adding in the old definition of that function from vanilla OXC, and that remedies the issue. I have successfully built OXCE+ this way as well.
Title: Re: Build on Windows without VS
Post by: Yankes on August 19, 2018, 05:31:09 pm
To stay on topic, I have in fact succeeded in building on Windows without VS. For this I used msys2/MinGW-w64.

I did have to edit some files to get it to work:

- src/Makefile.gcc-pch
On line 25, change
Code: [Select]
CXXFLAGS ?= -Wall -Wextra -Wno-unused-function -O2 -rdynamic -g -D_DEBUGto
Code: [Select]
CXXFLAGS ?= -Wall -Wextra -Wno-unused-function -O2 -g -D_DEBUGThe -rdynamic flag apparently doesn't exist in MinGW (https://stackoverflow.com/questions/17483306/compiling-with-mingw-unrecognized-command-line-option).

On line 30, change
Code: [Select]
LIBS = $(shell $(PKG-CONFIG) --libs sdl yaml-cpp) -lSDL_gfx -lSDL_mixer -lSDL_image -lGLto
Code: [Select]
LIBS = $(shell $(PKG-CONFIG) --libs sdl yaml-cpp) -lSDL_gfx -lSDL_mixer -lSDL_image -lopengl32 -lshlwapi
- src/Engine/Zoom.cpp
Find the following lines
Code: [Select]
#ifdef __GNUC__
#if (__i386__ || __x86_64__)
#include <cpuid.h>
#endif
#endif
and delete them. I built using the x86_64 toolchain, which causes a problem with this. Chalk it up to A Windows Thing.

To build, go into src/ and invoke
Code: [Select]
make -f Makefile.gcc-pch

Unfortunately, this process does not at this time seem to work for OpenXComExtended+. When linking it errors out with
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../obj/linux/WarningMessage.o: in function `OpenXcom::WarningMessage::WarningMessage(int, int, int, int)':
d:\Games\OpenXCOM\OXCE+\src/Battlescape/WarningMessage.cpp:41: undefined reference to `OpenXcom::Text::setWordWrap(bool, bool)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../obj/linux/CannotReequipState.o: in function `OpenXcom::CannotReequipState::CannotReequipState(std::vector<OpenXcom::ReequipStat, std::allocator<OpenXcom::ReequipStat> >)':
d:\Games\OpenXCOM\OXCE+\src/Battlescape/CannotReequipState.cpp:73: undefined reference to `OpenXcom::Text::setWordWrap(bool, bool)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../obj/linux/InfoboxState.o: in function `OpenXcom::InfoboxState::InfoboxState(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)':
d:\Games\OpenXCOM\OXCE+\src/Battlescape/InfoboxState.cpp:58: undefined reference to `OpenXcom::Text::setWordWrap(bool, bool)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../obj/linux/AliensCrashState.o: in function `OpenXcom::AliensCrashState::AliensCrashState()':
d:\Games\OpenXCOM\OXCE+\src/Battlescape/AliensCrashState.cpp:67: undefined reference to `OpenXcom::Text::setWordWrap(bool, bool)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../obj/linux/InfoboxOKState.o: in function `OpenXcom::InfoboxOKState::InfoboxOKState(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)':
d:\Games\OpenXCOM\OXCE+\src/Battlescape/InfoboxOKState.cpp:70: undefined reference to `OpenXcom::Text::setWordWrap(bool, bool)'
C:/Programs/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../obj/linux/BuildNewBaseState.o:d:\Games\OpenXCOM\OXCE+\src/Geoscape/BuildNewBaseState.cpp:136: more undefined references to `OpenXcom::Text::setWordWrap(bool, bool)' follow
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile.gcc-pch:42: ../bin/openxcom] Error 1
It seems the function declaration of setWordWrap has changed to accept a third argument, which VC apparently accepts but g++ does not.

Edit: I tried adding in the old definition of that function from vanilla OXC, and that remedies the issue. I have successfully built OXCE+ this way as well.
For OXCE and OXCE+ you probably should use `src/Makefile.mingw`or `Makefile.mingw-w64` and more importantly cleanup all build files before building different branch.
Title: Re: Build on Windows without VS
Post by: BTAxis on August 19, 2018, 06:07:05 pm
For OXCE and OXCE+ you probably should use `src/Makefile.mingw`or `Makefile.mingw-w64` and more importantly cleanup all build files before building different branch.

I've tried this, but unfortunately I end up with pages and pages of undefined reference errors that I don't know how to fix. It seems YAML related though.
Title: Re: Build on Windows without VS
Post by: Yankes on August 19, 2018, 06:20:19 pm
I've tried this, but unfortunately I end up with pages and pages of undefined reference errors that I don't know how to fix. It seems YAML related though.
And did you do "and more importantly cleanup all build files before building different branch." before this?
Title: Re: Build on Windows without VS
Post by: BTAxis on August 19, 2018, 06:34:58 pm
Yes, of course. make -f Makefile.gcc-pch clean before switching to the other makefile.
Title: Re: Build on Windows without VS
Post by: Yankes on August 19, 2018, 06:38:57 pm
Yes, of course. make -f Makefile.gcc-pch clean before switching to the other makefile.
But it not look like this, because if you do OXCE+ build your compilation would return error not linking stage.
Title: Re: Build on Windows without VS
Post by: BTAxis on August 19, 2018, 07:11:57 pm
I'm pretty sure I am not editing Makefile.mingw correctly (I don't really speak make). You were right about not cleaning properly earlier though, because it turns out the edit to Text.cpp/h I mentioned was not necessary.

Anyway this (https://pastebin.com/AcCYXT1t) is the makefile I'm attempting to use (I only edited the paths to SDL, Boost and YAML). Again, fairly sure it's to do with YAML because the makefile points to sources that don't exist.
Title: Re: Build on Windows without VS
Post by: Yankes on August 19, 2018, 08:01:03 pm
OXCE compile yaml from sources: `git clone https://github.com/jbeder/yaml-cpp.git` (you need run this command in correct dir to match makefile)
Title: Re: Build on Windows without VS
Post by: BTAxis on August 19, 2018, 10:25:09 pm
OXCE compile yaml from sources: `git clone https://github.com/jbeder/yaml-cpp.git` (you need run this command in correct dir to match makefile)

Actually no, that's not needed with msys2. It provides the yaml-cpp package via its package manager.

I've worked out how to do it now. This (https://pastebin.com/bnqFpdWL) makefile will build the game without fuss. Okay, a couple of warnings. But it works.

Thanks for your input Yankes, you've been a great help.
Title: Re: Build on Windows without VS
Post by: Yankes on August 19, 2018, 11:24:15 pm
And what version is avaialbe in this package? One reason why I use sources from github is because some environments had outdated version.
As bonus new version use C++11 and do not depend on Boost.
Title: Re: Build on Windows without VS
Post by: BTAxis on August 20, 2018, 11:45:42 am
And what version is avaialbe in this package? One reason why I use sources from github is because some environments had outdated version.
As bonus new version use C++11 and do not depend on Boost.

Code: [Select]
$ pacman -Ss yaml-cpp
mingw32/mingw-w64-i686-yaml-cpp 0.6.2-1 [installed]
    A YAML parser and emitter in C++ matching the YAML 1.2 spec (mingw-w64)
mingw32/mingw-w64-i686-yaml-cpp0.3 0.3.0-2
    A YAML parser and emitter in C++ matching the YAML 1.2 spec (mingw-w64) - old version
mingw64/mingw-w64-x86_64-yaml-cpp 0.6.2-1 [installed]
    A YAML parser and emitter in C++ matching the YAML 1.2 spec (mingw-w64)
mingw64/mingw-w64-x86_64-yaml-cpp0.3 0.3.0-2
    A YAML parser and emitter in C++ matching the YAML 1.2 spec (mingw-w64) - old version

It seems to work out for me, I've played on my binary and noticed no issues.
Thanks for the tip about Boost, removing it worked just fine.
Title: Re: Build on Windows without VS
Post by: Jakeoff on October 21, 2019, 11:02:40 pm
Development in Visual Studio is not an easy task. Constantly a bunch of bugs
Title: Re: Build on Windows without VS
Post by: Lewis-H on September 30, 2020, 01:25:41 pm
First, you need to get the latest msbuild.
You can get it from Visual Studio 2017 download page.  On the bottom, click “Other Tools and Frameworks”, then choose “Build Tools for Visual Studio 2017”.
Direct download link

Start that setup file (vs_buildtools_xxx.exe), and choose “Web Development Build Tools”.



After installing, you will get a new command prompt in the start menu, called “Developer Command Prompt for VS 2017”.  Use it to start your command prompt, as it will add to path all required folders to run msbuild from anywhere.

Go to your folder with your solution sln file, and just type msbuild.  It will automatically start building the sln files.

If you use nuget packages, you will get errors about missing packages.  You may have read somewhere that you only need to type “msbuild /t:restore”, but I think that it’s only works for .NET Core solutions, it does nothing for Studio 2017 classic framework projects.

Now you need an additional file: nuget.exe, 

I use the latest version, 4.1.  The download is not a setup, it’s directly the nuget executable.  Only 1 file is needed.

I suggest to save it somewhere available in your path from DOS, maybe at the same place that msbuild was installed, [C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin].

Now, get back to your sln folder, and just type “nuget restore”.  The “packages” folder will be created, and required nuget packages downloaded there.

You’re ready to try msbuild again.
Title: Re: Build on Windows without VS
Post by: dhinvid on August 03, 2022, 01:44:35 pm
I have in fact succeeded in building on Windows without VS. For this I used msys2/MinGW-w64.