NI Linux Real-Time Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Installing gFortran Compile Tools on NI Linux Real-Time

Below is a tutorial that walks a user through installing gcc with gFortran compile tools configured.  It was tested and works on a cRIO 9039, and may not work on cRIOs with less storage and memory available.  The cRIO 9039 has 16GB of storage and 2GB of memory.

This is not supported by NI.  This is a single example and is not tested across multiple targets - consider it to be a proof of concept.  These steps are intended for advanced users.  Please do not contact NI Support with questions on these steps.  If you do have questions please post in the comments here, and I will do my best to answer them.

Execute the following commands either in a terminal window on the target using the Embedded UI or over an SSH connection.

Installing Tools

rm /usr/bin/lastb

opkg update

opkg install gcc gcc-symlinks

opkg install cpp cpp-symlinks

opkg install g++ g++-symlinks

opkg install bzip2

opkg install bzip2-dev

opkg install libbz2-dev

opkg install libc6

opkg install libc6-utils

opkg install libgcc-s-dev

opkg install binutils

opkg install util-linux

opkg install binutils-symlinks

opkg install git

opkg install libstdc++-dev

opkg install make

opkg install wget

opkg install automake

Get a Copy of the GCC Source

wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.3/gcc-4.8.3.tar.gz

Extract the GCC Source

tar -xvf gcc-4.8.3.tar.gz

Configuration for the Build

cd gcc-4.8.3

./contrib/download_prerequisites

./configure --prefix=$HOME/gcc-v4.8.3 --enable-languages=c,c++,fortran --disable-multilib

ulimit -s unlimited

Add Swap Space

fallocate -l 1G tmpswap

mkswap tmpswap

swapon tmpswap

Following the swapon command you may see a warning similar to the one shown below.  This can be disregarded.

Untitled picture.png

Build and Install

make

make install

export PATH=$PATH:/home/admin/gcc-v4.8.3/bin

At this point you should be able to compile and execute gFortran code on your target.

Regards,
Kelly B.

National Instruments
Comments
ScotSalmon
Active Participant
Active Participant
on

Impressive!

BradM
Active Participant
Active Participant
on

rm /usr/bin/lastb
I'm curious why this is required

opkg update
opkg install gcc gcc-symlinks
opkg install cpp cpp-symlinks
opkg install g++ g++-symlinks
opkg install bzip2
opkg install bzip2-dev
opkg install libbz2-dev
opkg install libc6
opkg install libc6-utils
opkg install libgcc-s-dev
opkg install binutils
opkg install util-linux
opkg install binutils-symlinks
opkg install git
opkg install libstdc++-dev
opkg install make
opkg install wget
opkg install automake

This should be replacable with opkg update && opkg install packagegroup-core-buildessential git

virtuald
Member
Member
on

There's actually a bitbake recipe for gfortran, which allows you to cross-compile an IPK (eg, no RIO memory requirements). I've included instructions on using bitbake et al for this purpose here: https://github.com/robotpy/roborio-packages/tree/2016/atlas_libs

BradM
Active Participant
Active Participant
on

virtuald, you should issue pull-requests for those changes since you've already done the work

virtuald
Member
Member
on
Kelly_B
NI Employee (retired)
on

The rm line is needed because without it one of the utils installs fill fail with an error that an initialization file already exists in that location.  Removing the file ahead of time prevents the error and allows the install to proceed successfully. 

I don't have a screenshot or the exact text of the error at the moment, but if you would like me to post it I can do that.

Regards,
Kelly B.

National Instruments
BradM
Active Participant
Active Participant
on

Hmm, interesting, it would be interesting to know what version of the OS you're using while doing this work, it could be indicative of an OpenEmbedded bug (either missing PROVIDES or two components pulling in the same file)

JiPé
Member
Member
on

Hi Kelly,

Thanks for this amazing job and your step-by-step explanation!

I followed this procedure on a 9033 and it seems to work fine.

(I had to remove some software like scan engine to get rid of a “segmentation fault” issue due to a lack of disk space).

I managed to compile a simple shared library on the cRIO via SSH (I am using Putty) and I am trying to call it with LabVIEW 2016. I compiled the library directly under:

/usr/local/lib/MyLib.so

With the line: gfortran -shared -Bdynamic -Bsymbolic -mtune=atom -fno-underscoring -fPIC -o MyLib.so MyLib.f90

 

Unfortunately, LabVIEW return me an error saying I need a missing library: libgfortran.so.3.

   “Libgfortran.so.3:cannot open shared object file: No such file or directory”

This library exists on my target and I tried to add it manually to the system in various ways:

   export LD_PRELOAD=/home/admin/gcc-v4.8.3/lib64/libgfortran.so.3

   export SHLIB_PATH=$SHLIB_PATH:/home/admin/gcc-v4.8.3/lib64/libgfortran.so.3

   export PATH=$PATH:/home/admin/gcc-v4.8.3/lib64/libgfortran.so.3

And in addition, I used this command to make sure it’s linked properly:

   ldconfig -n -v /home/admin/gcc-v4.8.3/lib64/

 

But it’s still not working… I am quite puzzled by all that.

As I installed everything with your directives and I compiled directly on the cRIO (64bits) all the libraries should be 64bits right?

I must explain, I’m not doing all this for pleasure, I’m an NI partner. A customer asked me a POC before buying a cRIO. The main point would be to call a Fortran library ‘.so’ under LabVIEW RT. The customer will keep it secret by releasing only the .so to me (the algorithm seems proprietary) and I’ll be in charge of integrating it with physical inputs and outputs. I’m reaching my limits here. I had to remind me all the Linux stuff I was doing 10 years ago, when I was an AE and to code with a keyboard :-). I can call a ‘.so’ made in C and compiled with GCC without a problem.

 

Could you provide me any help or advice about this missing library?

I think we're pretty close to doing it.

LabVIEW Architect - Founder and CEO - Phalanx
---------------------------------------------------------------------------------------------------
Tout le succès d'une opération réside dans sa préparation. - Sun Tzu
JiPé
Member
Member
on

Hi guys,

I managed to make it work last night!

At least, I found a workaround.

First, the “.so” called needs to have a “C biding” type to be called by LabVIEW. Like explained here:

https://gcc.gnu.org/onlinedocs/gfortran/Interoperable-Subroutines-and-Functions.html#Interoperable-S...

Second, we need (weirdly) to call a function of “libgfortran.so.3” to initialize it prior the call of our library. Like explained here:

https://gcc.gnu.org/onlinedocs/gfortran/Non-Fortran-Main-Program.html

I used the function “_gfortran_set_args” inside this library with the inputs 0 and 0 as pointers.

In LabVIEW I first call libgfortran library, I use the error cluster to respect the execution order. Then I call my library written with C binding format and it’s working!

compactRIO is amazing!

I’ll write a post with pictures and a little more explanation later on the forum and on Phalanx website.

LabVIEW Architect - Founder and CEO - Phalanx
---------------------------------------------------------------------------------------------------
Tout le succès d'une opération réside dans sa préparation. - Sun Tzu
Sicitronic
Member
Member
on

Hi,

 

I am trying to do the process into a cRIO-9049 (NI Linux Real-Time x64 4.14.87-rt49-cg-7.1.0f0-x64-41), but I get the following error after executing the "make" command.Make Issue.png

 

Any idea?

 

Thank you!

Contributors