Howto:Build and run FlightGear on Raspberry Pi 4: Difference between revisions

Jump to navigation Jump to search
Line 30: Line 30:
sudo rpi-update          (DO NOT USE)
sudo rpi-update          (DO NOT USE)
</syntaxhighlight>
</syntaxhighlight>
==Compiling ==
===When to recompile/build===
Watch for release announcements [1] or subscribe to the flightgear-commitlogs mailing list [2] (lots of emails).
[1]  https://www.flightgear.org/category/news/
[2]  https://sourceforge.net/projects/flightgear/lists/flightgear-commitlogs
===Download_and_compile.sh===
[[Scripted Compilation on Linux Debian/Ubuntu]]
There can be a complication when using a version of FlightGear that has been built with download_and_compile.sh. This involves the combination of  two situations; the version is being used and changes are being performed to files within the FlightGear build, furthermore the build is being updated at a later time. During updates, Git keeps an eye on any changes too files within this build. Git assumes that you are a software developer, of course this is no problem if you know what you are doing. So if Git sees a change or a new file is created, like to a joystick file, it thinks you are a developer and keeps track of changes. The issue shows up, after changes were performed, when download_and_compile.sh goes to update the FlightGear build. Git gets involved and needs to know how to integrate your changes with the changes from the update performed by download_and_compile.sh. An easy solution is to make a second copy of FlightGear to use and just update the original. Or make a copy of fgdate and use the FlightGear launcher to point to this working/running version of fgdata. Here we are assuming that the modified or created files are only within fgdata.
====Raspberry Pi OS 64-bit====
OSG will need patched, [[Howto:Build_and_run_FlightGear_on_Raspberry_Pi_4#Patching|OSG patch]]. If source files and folders were used for Raspbian 32-bit, delete the build and install folders.
FlightGear may fail to compile with the below error:
<syntaxhighlight>
/usr/bin/ld: ../../3rdparty/sqlite3/libfgsqlite3.a(sqlite3.c.o): in function `sqlite3_column_name16':
/media/pi/ea5ced60-d2bc-44fc-adb8-5781729826a1/flightgear/dnc-managed/flightgear/3rdparty/sqlite3/sqlite3.c:76778:(.text+0x16470): relocation truncated to fit: R_AARCH64_LD64_GOTPAGE_LO15 against symbol `sqlite3_value_text16' defined in .text section in ../../3rdparty/sqlite3/libfgsqlite3.a(sqlite3.c.o)
/usr/bin/ld: /media/pi/ea5ced60-d2bc-44fc-adb8-5781729826a1/flightgear/dnc-managed/flightgear/3rdparty/sqlite3/sqlite3.c:76778:
collect2: error: ld returned 1 exit status
</syntaxhighlight>
The fix is to edit this file; <code>/flightgear/dnc-managed/flightgear/3rdparty/sqlite3/CMakeLists.txt</code>. Within CMakeLists.txt, change <code>fpic</code> to <code>fPIC</code>
Scott wrote:
<blockquote>
The main difference between -fpic and -fPIC is that little-pic generates
faster code, but severely limits you to a small address space (e.g. 64KB
data buffer).  big-PIC will leverage a much larger address space (e.g.
2GB) and therefore requires more address bytes to reach the full address
range.  More address bytes equates to a small performance hit.
I don't program the ARM enough to know what the hard limit is when using
-fpic, but whatever the limit is, the compiler is telling you that this
limit has been exceeded.
I always use -fPIC as it is rarely worth the fuss to try -fpic first and
then switch to -fPIC when that fails.
Scott
</blockquote>
Now follow the instruction on the download_and_compile.sh page.
===Raspbian===
This is not meant to be a fast copy and past compiler method. Below, is meant to be compiling more by learning or understanding. However, there will be plenty of opportunities for copying and pasting.
===Dependencies===
[[Howto:Build_and_run_FlightGear_on_Raspberry_Pi_4#Download_and_compile.sh|Download_and_Compile.sh]] does a good job of installing the needed dependencies, as of 01/03/2021. Refer to that script for more information.
====Extra Information====
The command <code>dpkg -s package_name</code> can be used, in the terminal to verify if a package is installed. Replace 'package_name' with the name of the dependency from the above list.
Before installing any missing dependencies, update Raspbian per the above (Download_and_Compile.sh will do this for you) [[Howto:Build_and_run_FlightGear_on_Raspberry_Pi_4#Update_Raspbian|Update Raspbian]] instructions. The below terminal command can be used to install any missing dependencies:
<syntaxhighlight lang="bash">
sudo apt-get install package_name
</syntaxhighlight>
===git===
A popular method to control software revisions is with <code>git</code>. Some basic knowledge of <code>git</code> is helpful and interesting. So, try to learn the basics.
{| class="wikitable"
|-
! '''<big>♦♦♦ Warning ♦♦♦</big>'''
|-
| Edward wrote:
<blockquote>
Please only run 'git clone' once ever!  That is once per machine, new
install, etc.  Otherwise SourceForge will permanently blacklist your IP
address.  The strain on their infrastructure with our huge repositories is
far too much.
</blockquote>
|}
When using some <code>git</code> commands you might be prompted by <code>git config --global user.email "you@example.com"</code> and or <code>git config --global user.name "Your Name"</code>. In that case a user account is needed at [http://www.github.com www.github.com]. So, before starting the compiling process it would be advisable to first go to their web page and create a free user account. After acquiring the user account, use the below commands (one at a time) in order to satisfy the above <code>git</code> requirement. Replace 'you@example.com' with your <code>git</code> account email address and also replace 'Your Name' with the user name for this account. It might be best to choose a user name without a space in it.
<syntaxhighlight lang="bash">
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
</syntaxhighlight>
Link to <code>git</code> [https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration configuration and customization] information page.
Some Essential git commands:
* <code>git status</code>
* <code>git checkout</code>
* <code>git pull</code>
** Can be used to update the fgmeta folder when using the download_and_compile.sh script. Use this command from within the fgmeta folder.
* <code>git reset --hard</code>
* <code>git log</code>
Also see [[FlightGear Git]].
===Copy Path(s)===
[[File:Copy Path(s).jpeg|thumb|150px|Easy way to copy the path of a file or folder.]]
During the manual compiling process there will be times when the path of a file or folder is needed for a Terminal command. One easy GUI short cut is to right click on the file or folder to pull up an option list. Find the option 'Copy Path(s)' and click on it. The path of the file or folder will be copied. Next, in the Terminal, click on 'Edit' at the top of the Terminal window and then click on 'Paste' in order to past the link into the Terminal. See the screen shot to the left.
===Location of Files===
The SD card performs well for common computer tasks and running FlightGear. However, compiling large programs could wear out the SD card before it's time. This is an excellent application for a SSD drive. Especially if many compiled versions of FlightGear are planned. For that reason this Wiki will choose to compile and install FlightGear on a [[Howto:Build_and_run_FlightGear_on_Raspberry_Pi_4#Hard_Drives|SSD drive]].
This is a good time to create some needed folders on the SSD. For this Wiki the folder '''FlightGear''' was created in the root of the SSD. Within this newly created folder '''FlightGear''', create two more folders named '''fg-install''' and '''source'''. Use your favorite method to navigate and create folders, whether it be the Terminal or GUI. Furthuremore, these files can have other names as long as those other names are globally used.
===Build Order===
PLIB, OSG, SimGear, FlightGear
===Patching; OSG patch example===
There could come a time when the source needs to be patched before compiling. In this case the <code>patch</code> command can be used along with it's argument <code>-p</code>. For example; the OpenSceneGraph-3.4.0 requires the '0007-Explicit-signed-char-type-for-portability-base64.patch' patch, in order for it to compile for the ARM architecture.
In this example, the patch can be found at this link: [https://sources.debian.org/patches/openscenegraph-3.4/3.4.1+dfsg1-5/ OpenSceneGraph-3-4-0 patch]. The <code>download</code> link for '0007-Explicit-signed-char-type-for-portability-base64.patch' is what we are looking for. This file can be downloaded with the <code>wget</code> command as seen below:
<syntaxhighlight>wget --trust-server-names https://sources.debian.org/src/openscenegraph-3.4/3.4.1+dfsg1-5/src/osgPlugins/osgjs/Base64.cpp/</syntaxhighlight>
Place, the above patch file, into the the source root folder of OpenSceneGraph-3-4-0.
The argument ,<code>-p</code> adjusts the path of the patch. Below is an example of a snippet from a patch. Reference the line ,<code>--- openscenegraph-3.4.orig/src/osgDB/ConvertBase64.cpp</code>. The folder <code>openscenegraph-3.4.orig/</code> can not be used, in our example. In this case, one of the path folders need to be ignored, hence <code>-p1</code>. If two path folders needed to be ignored; <code>-p2</code>.
<syntaxhighlight>Index: openscenegraph-3.4/src/osgDB/ConvertBase64.cpp
===================================================================
--- openscenegraph-3.4.orig/src/osgDB/ConvertBase64.cpp
+++ openscenegraph-3.4/src/osgDB/ConvertBase64.cpp
@@ -28,7 +28,7 @@ namespace osgDB
    int base64_decode_value(char value_in)
    {
-        static const char decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
+        static const signed char decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
        static const char decoding_size = sizeof(decoding);
        value_in -= 43;
        if (value_in < 0 || value_in > decoding_size) return -1;</syntaxhighlight>
Navigate the terminal into the root folder of OpenSceneGraph-3.4.0 source. Side note: the <code>patch</code> command might need to be installed. Now enter the below command into the terminal:
<syntaxhighlight>patch -p1 <0007-Explicit-signed-char-type-for-portability-base64.patch</syntaxhighlight>
===OpenRTI===
OpenRTI is optional. If you're using it, you need to compile it before SimGear (and therefore, before FlightGear). It's orthogonal to OSG.


==Backtrace using gdb: and Download_and_compile.sh==
==Backtrace using gdb: and Download_and_compile.sh==
320

edits

Navigation menu