Author Topic: Guide to Building from Source  (Read 13004 times)

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2350
  • OPHD Lead Developer
    • LairWorks Entertainment
Guide to Building from Source
« on: November 17, 2019, 10:47:39 PM »
I started putting together a guide for building OutpostHD from source: https://wiki.outpost2.net/doku.php?id=outposthd:building_from_source

Aside from what to do with NAS2D and the data assets, it should be pretty complete. Please let me know if you have any issues with the steps used in this guide.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Guide to Building from Source
« Reply #1 on: November 18, 2019, 01:55:23 PM »
Instructions look clear so far.

When cloning the OPHD Git repository, is there an option somewhere to do a recursive clone? If so, that should automatically fetch the NAS2D library code as well. From the command line it is specified with --recursive. From a GUI (maybe TortoiseGit?) there was a checkbox for "recursive".

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2350
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Guide to Building from Source
« Reply #2 on: November 18, 2019, 07:43:49 PM »
There is, I never really investigated what that option was. Through visual studio there is also a recursive option, I just don't remember exactly where.

Offline Goof

  • Jr. Member
  • **
  • Posts: 57
Re: Guide to Building from Source
« Reply #3 on: November 23, 2019, 06:24:01 AM »
Hi guys/girls

Just to add a Prerequisites for non english devs.
When you launch the command
Code: [Select]
vcpkg install glew:x86-windows glew:x64-windows physfs:x86-windows physfs:x64-windows
The tool warn about the missing english language package
Code: [Select]
Warning: The following VS instances are excluded because the English language pack is unavailable.
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
Please install the English language pack.

Add the english language to fix it and run the command again .



Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Guide to Building from Source
« Reply #4 on: November 23, 2019, 07:47:33 PM »
Huh, I wonder what causes that.

Thank you for the report.

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2350
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Guide to Building from Source
« Reply #5 on: February 09, 2020, 11:59:43 AM »
I updated the Building From Source article on the wiki. Since we moved everything to using vcpkg for dependencies and have now included NAS2D as part of the OutpostHD solution it should be a lot easier to build.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Guide to Building from Source
« Reply #6 on: February 09, 2020, 01:18:56 PM »
I was about to add a note about running the InstallVcpkgDeps.bat file to install the vcpkg dependencies, though I just remembered that's already done automatically now as part of the NAS2D build step.

Does the Git integration with Visual Studio do a recursive Git checkout by default? I'm uncertain if it will really fetch NAS2D by default, or if an extra step is needed there.

Offline Goof

  • Jr. Member
  • **
  • Posts: 57
Re: Guide to Building from Source
« Reply #7 on: February 10, 2020, 01:26:10 AM »
It seems to work as i only clone the OPHD repository and import the 2 projects.

Offline Vagabond

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1013
Re: Guide to Building from Source
« Reply #8 on: February 10, 2020, 10:45:28 AM »
Quote
Does the Git integration with Visual Studio do a recursive Git checkout by default? I'm uncertain if it will really fetch NAS2D by default, or if an extra step is needed there.

Hooman, I tested this out. When cloning the repository using Visual Studio's built in Git functions, it automatically pulled NAS2D. I could not compile OPHD out of the box because it was missing the SDL dependency. I assume this is because SDL is installed via vcpkg and I don't believe vcpkg dependencies are automatically downloaded like nuget packages, but I didn't look into it at all.

Glad to see work going into streamlining OPHD's build flow.

-Brett

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2350
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Guide to Building from Source
« Reply #9 on: February 10, 2020, 07:28:49 PM »
I haven't looked at the batch file as I don't have vcpkg installed in the environment so calling vcpkg from the command line results in a "command not found" type of issue so I haven't paid any attention to it. In the build setup on the Wiki I have a guide to install vcpkg, integrate with Visual Studio and then issue the commands to download and build the dependencies.

I'm still annoyed that the ttf and mixer dependencies link against debug sdl2 in release mode, so waiting on a patch for that but I doubt that'll take too long, the vcpkg team seems really responsive to those kinds of issues.

Offline The_Blight

  • Newbie
  • *
  • Posts: 10
Re: Guide to Building from Source
« Reply #10 on: April 21, 2020, 04:42:59 PM »
I've built the OPHD project on Linux (Ubuntu 19.10). However, I did build this project also a long time ago, so some dependencies might already be on my system.
I do know I relied heavily on the Docker instructions but ran them on my own machine and if it couldn't find something, I used a search engine to look for the missing apt package.

These are the steps I did to be able to build and run the "openhd.exe" (which probably shouldn't be named .exe on Linux  ;) ).

Code: [Select]
git clone https://github.com/OutpostUniverse/OPHD.git
cd OPHD
git submodule init
git submodule update
cd nas2d-core
make
cd ..
make
wget -4 https://www.outpost2.net/files/ophd/data.zip
unzip data.zip -d data
./openhd.exe

Had a lot of fun trying to play on a Mars like planet, died twice already though  ;D, and it's so reminiscient of the old days, only better!




Hope this helps someone!


Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Guide to Building from Source
« Reply #11 on: April 22, 2020, 01:12:40 AM »
Oh hey, interesting to hear about your experiences. I'm glad you were able to get that built and running.


I would be curious to know if there is something we can do to make building the project easier, or more obvious. In particular, where did you spend most of your time getting it working?


At one point I did add makefile rules to install dependencies using apt, though it's buried in the NAS2D makefile, so probably not super obvious when trying to build OPHD. The two projects have the same set of dependencies. There's probably more we can do to streamline first time setup.

Offline The_Blight

  • Newbie
  • *
  • Posts: 10
Re: Guide to Building from Source
« Reply #12 on: April 22, 2020, 11:49:14 AM »
Hi Hooman,

Well the place I looked for build instructions initially was on the GitHub page, for an INSTALL.MD or a reference on the Wiki, but couldn't find any there.
Naively I tried to do "make" in the root directory but that didn't work.
After some Googling I found the link to the docker setup.
Even though I work with git on a professional basis, I didn't know git submodules were a thing, so it took some figuring out.
This gave me the clue that the nas2d probably was a dependency, and that I should build that first.
After that I was able to compile OPHD, and then was able to launch the executable, only to be greeted with an error regarding a missing asset.  :)
The data.zip is mentioned somewhere in the forum, but that too I had forgotten about.
The -4 flag in the wget command is so that it defaults to IPv4, as it seems to hang when I don't specify it.

I've now also got a debug build working in Eclipse (freshly downloaded 2020-03 version, c++ development edition):
- Import as Makefile Project (select the folder which contains the topmost makefile, this is usually the folder in which you checked out from git.)
- This should allow you to build the code based on the makefile (it will call the "all" targate by default)
- Should you require a debug build (handy if one wants to develop), we need to build our code with the debug information contained in it.
- To do so, edit the MakeFile, by adding the following target below the "all" target and its configuration:

Code: [Select]
.PHONY: debug
debug: DEPFLAGS += -g -O0
debug: $(EXE)

This appends some extra flags to the DEPFLAGS variable, the -g flag makes sure the debug info is added, and the -O0 (minus oh zero) flag makes sure no code optimizations when compiling are done so the debugger will still see everything as-is.

Save the makefile.

Then in Eclipse, in Project > Properties, select the C/C++ Build, and select the "Behavior" tab.
Here change the "Build (incremental build)" value from "all" to "debug".

Rebuild your code.

Set a breakpoint somewhere and launch the Debug configuration:



« Last Edit: May 02, 2020, 02:56:21 PM by The_Blight »

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Guide to Building from Source
« Reply #13 on: May 21, 2020, 09:38:37 PM »
Sorry if this reply is a little slow coming.

I was thinking about adding a debug build target to the makefile, but then I realized this can be done with the already setup make variables:
Code: [Select]
make CXXFLAGS_EXTRA="-g -O0"

Additionally, you can change the build folder so the debug build intermediate files don't interfere with release builds. That way you can switch between build configurations without having to do a clean and full rebuild.
Code: [Select]
make CXXFLAGS_EXTRA="-g -O0" BUILDDIR=".build/debug/"

I was thinking about adding additional targets to set those variables, though I realized there can be quite a few targets for some projects. It's not so noticeable for OPHD itself, but for the NAS2D dependency, there are more build targets. In particular: all, test, check, test-graphics, run-test-graphics. It seemed to make less sense to create special targets for each of them. Mind you, that's basically what was done for the instructions to build the Docker images. Guess I haven't really made up my mind about which direction to go. It does seem more user friendly to have a build target name, rather than specify the details of the build flags.

Anyway, this kind of gets me thinking the Linux side of things could use a bit more support for build configurations.



Another thought I had was to detect when the submodule is missing, inform the user, and try to automatically initialize and download the git submodule. That should reduce the potential for confusing problems for a first time install.

Offline Kyrros

  • Newbie
  • *
  • Posts: 8
Re: Guide to Building from Source
« Reply #14 on: May 27, 2020, 10:21:11 AM »
Been a while since I've last looked at this project, also very glad you're doing better now!
Anywho, built a new personal/gaming rig awhile back, so I don't have Visual Studio (or VCC) installed since this is a recreational box and not a work box.

Had some trouble with the initial bootstrap-vcpkg.bat, seems it calls a sub .bat, bootstrap.ps1.bat and I kept getting thrown this...

"Could not detect a Windows SDK / TargetPlatformVersion"

here's the block where that exception comes from.

Code: [Select]
    # Selecting
    if ($withWinSDK -ne "")
    {
        foreach ($instance in $validInstances)
        {
            if ($instance -eq $withWinSDK)
            {
                return $instance
            }
        }

        throw "Could not find the requested Windows SDK version: $withWinSDK"
    }

    foreach ($instance in $validInstances)
    {
        if (!$DisableWin10SDK -and $instance -match "10.")
        {
            return $instance
        }

        if (!$DisableWin81SDK -and $instance -match "8.1")
        {
            return $instance
        }
    }

    throw "Could not detect a Windows SDK / TargetPlatformVersion"
}

Had to add an OS specific SDK (in my case, Win10) to get it to work, may want to make a note of that in the "to add" list as well on the VCPkg page (since it also adds an additional ~2.7GB to the VS install download)

SEE ATTACHED IMAGE

Also, VCPkg sends 'anonymous' usage metric data back to Microsoft, maybe make a note to suggest including -disableMetrics parameter with the intial bootstrap-vcpkg call at the users discretion.
« Last Edit: May 27, 2020, 07:06:11 PM by Kyrros »

Offline Kyrros

  • Newbie
  • *
  • Posts: 8
Re: Guide to Building from Source
« Reply #15 on: May 27, 2020, 06:49:23 PM »
Several build attempts later... heh.

So, VCPkg does not natively execute from VS2019, even after installation/integration, I had to add the VCPkg directory to my %PATH% manually before the build/rebuild would attempt to run correctly.

After resolving the 'vcpkg not found' error, I was able to run a proper build, but then it, too, failed for (finally) a legitimate reason.  NAS2D fails to build, so then when OPHD try, it, too, then fails due to reference errors.

VS2019 error
The command "..\Package.bat C:\Program Files (x86)\GAMES\Outpost HD\OPHD\x64\Debug\NAS2D.lib x64 Debug:VCEnd" exited with code 1.
 
Build output snippet
Code: [Select]
1>Compress-Archive : The path 'nas2d-1.5.0-1379-g2299b30-Windows.Files.(x86)\GAMES' either does not exist or is not a
1>valid file system path.
1>At line:1 char:1
1>+ Compress-Archive -Path 'NAS2D.lib', 'include/' -DestinationPath 'nas2 ...
1>+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>    + CategoryInfo          : InvalidArgument: (nas2d-1.5.0-137...les.(x86)\GAMES:String) [Compress-Archive], InvalidO
1>   perationException
1>    + FullyQualifiedErrorId : ArchiveCmdletPathNotFound,Compress-Archive
1>
1>A duplicate file name exists, or the file
1>cannot be found.

The 'C:/Program Files (x86)/GAMES' reference looks like it's been truncated somehow (error'd to "nas2d-1.5.0-1379-g2299b30-Windows.Files.(x86)\GAMES").... I isolated the line from the referenced Package.bat file below


Code: [Select]
powershell -Command "Compress-Archive -Path 'NAS2D.lib', 'include/' -DestinationPath '%PackageName%' -Force"

... possible syntax error?

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2350
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Guide to Building from Source
« Reply #16 on: May 27, 2020, 07:55:12 PM »
Could be, but you have it in Program Files which is a restricted set of directories in Windows 7+ -- Windows 10 enforces this even more strictly. Try building from a location outside of Program Files and see if you get any changes?

Thank you for your patience with this. I generally assume that anybody trying to build OutpostHD would already have Visual Studio 2019 installed.

Adding vcpkg to the environment path is something I need to add to the Wiki documentation -- it's a bit lacking since I originally wrote it and we've improved the build process considerably since I first started using vcpkg. This will help me improve documentation.

Offline Kyrros

  • Newbie
  • *
  • Posts: 8
Re: Guide to Building from Source
« Reply #17 on: May 27, 2020, 09:26:31 PM »
Oh yeah, I definitely remember the 'old' build days, haha.

I run VS in admin to avoid access error like that.  I moved to a different disk but the same path, same error, renamed to a simpler path, it works, turns out pathnames with spaces is what was causing the error. Now I'm finally just getting regular old code errors it seems.

Code: [Select]
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(174,8): error C2039: 'string': is not a member of 'std'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\vector(24): message : see declaration of 'std'
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(174,15): error C2065: 'string': undeclared identifier
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(174,15): error C2146: syntax error: missing ';' before identifier '_popRole'
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(174,15): error C2065: '_popRole': undeclared identifier
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(177,44): error C2065: '_popRole': undeclared identifier
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(178,46): error C2065: '_popRole': undeclared identifier
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(179,46): error C2065: '_popRole': undeclared identifier
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(183,14): error C2039: 'runtime_error': is not a member of 'std'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\vector(24): message : see declaration of 'std'
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(183,98): error C2065: '_popRole': undeclared identifier
D:\GAMES\OPHD\OPHD\PopulationPool.cpp(183,27): error C3861: 'runtime_error': identifier not found

The rest of the .cpp's seem to do just fine.

Looks like someone forgot to add #include <string> and #include <stdexcept> statements before/after they were done with PopulationPool.cpp file. Thankfully an easy fix, assuming by the std:: that the standard library was indeed intended.

Edited the file on my end, and it compiled just fine.

Now it's some sort of on execution error with the .exe itself... not familiar with this one, though.

SEE ATTACHED IMAGE

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2350
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Guide to Building from Source
« Reply #18 on: May 27, 2020, 09:54:39 PM »
That was going to be my next question. Might need to make judicious use of '"'s in the scripts.

You need the assets. https://www.outpost2.net/files/ophd/data.zip

Extract everything into 'data' in the project root folder (e.g., the one with the solution file).

Odd that the include file isn't included properly. Works on my machine, a virtual windows environment, a virtual mac environment, a virtual linux environment and live linux environment. /me shrugs Oh well, will look into it further another time.

Offline Kyrros

  • Newbie
  • *
  • Posts: 8
Re: Guide to Building from Source
« Reply #19 on: May 28, 2020, 03:11:01 PM »
I couldn't get the data folder to work until I put it into the resultant compiled/output folder with the exe.

Where would you like playthrough feedback posted? Post a new 'issue' on Git? Start a thread here?
« Last Edit: May 28, 2020, 03:16:48 PM by Kyrros »

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2350
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Guide to Building from Source
« Reply #20 on: May 30, 2020, 01:20:35 PM »
Posting here is probably the best way to do it for now since the game is in heavy development. Open a new topic for issues you come across -- it's always helpful to get feedback from users! :D

Offline Archy

  • Newbie
  • *
  • Posts: 5
Re: Guide to Building from Source
« Reply #21 on: June 05, 2020, 05:55:36 AM »
Hey all, just got through setting up and building on a relatively new Windows machine.

I got all of my info from this post, and your guide to building from source on the wiki so thanks for that :) But I had the most trouble / time spent guessing, with the Visual Studio dependencies to get the vcpkg stuff sorted.

But yeah, fixed the same way Kyrros did. The only Individual components I had were:
MSVC v142 VS 2019 C++ x64/x86build tools (v14.26)
Windows 10 SDK (10.0.19041.0)
GitHub extension for Visual Studio
Git for Windows

As well as the "workload", Desktop Development with C++.   I know the workload was mentioned but I'm a bit out of the game so didn't immediately recognise what that word meant.
I believe when I tried to open the solution it prompted me to install that workload and so I let it do it's thing. I never actually click it manually.

I didn't have to change any PATH details, but I did have the problem where the includes needed to be added.  Now I haven't written anything in C++ for a long time so I just added them to PopulationPool.cpp as attached. And it ran with no probs!  Let me know if it really should be in one of the headers though.

Oh and I also didn't have any troubles with the data folder.  Although I did initially unzip the whole contents into that root folder (and not inside a 'data' folder) so I had to fix that up.

Time for a lookaround now!
« Last Edit: June 05, 2020, 06:08:33 AM by Archy »

Offline leeor_net

  • Administrator
  • Hero Member
  • *****
  • Posts: 2350
  • OPHD Lead Developer
    • LairWorks Entertainment
Re: Guide to Building from Source
« Reply #22 on: June 05, 2020, 10:29:15 AM »
Would appear that my setup has header pollution I need to address. Will look into it. And thanks for providing your experience! Will help me get the projects set up and the wiki updated to make it as seamless as possible.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Guide to Building from Source
« Reply #23 on: June 09, 2020, 08:32:18 AM »
Oh hey, that's a lot of useful feedback.

Good point about the Vcpkg usage metrics. I guess we should avoid letting it send anything by default. Would be nice to improve the setup and experience with Vcpkg.

Looks like the post build packaging code doesn't handle paths with spaces in them. Will have to fix that. Meanwhile, you can potentially ignore that error, or disable packaging. Packaging isn't needed to build and run. That's more for preparing a release after a successful build.

The missing includes sound legitimate, and you've made what seems like an appropriate fix. C++ has a funny way of handling imported code, where certain private details tend to leak. In particular, standard library headers are allowed to include other standard library headers and bring in more symbols than they are required to. This can lead to cases where a symbol being used was indirectly imported through these private details, and so can work by accident on some implementations. As each implementation of the C++ standard library is implemented differently, sometimes this sort of thing affects some versions of some compilers and not others. I'm guessing you compiled with a different version of the C++ standard library than our continuous integration builds are using. At any rate, it sounds like a mistake on our end. I'm kind of puzzling over this one though, since the error messages presented don't correspond well with the current version of the code. Maybe some version skew from recent edits. I'll have to investigate in more detail.


In terms of feedback, game play feedback is probably best posted here on the forums. For code bugs, you can post either here on the forums or open an issue on GitHub. These days, I'm probably responding faster to technical stuff on GitHub.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Re: Guide to Building from Source
« Reply #24 on: June 11, 2020, 06:25:45 PM »
The header includes should now be fixed on the master branch. (Seems I was initially looking at the wrong file, with a similar name, which is why the error messages didn't seem to line up with the code).

For Vcpkg Telemetry, it seems the Vcpkg page has detail on that. It sounds like it's kind of a Vcpkg installation or setup issue, so I'm not sure I want to make any specific code changes in OPHD or NAS2D. It probably doesn't make sense to second guess how the user setup their Vcpkg installation. It might be worthwhile to add a note to the documentation though. Curious what other people think about that.

An issue has been opened for the packaging issue where paths contains spaces.