Colmoschin94
Posts: 2
Joined: Fri Feb 01, 2019 3:29 pm

Help with compiling source

Fri Feb 01, 2019 3:40 pm

Hi Guys,
I recently bought a RPi 3B for an aviation project I am following, however I am not familiar with Linux or programming at all. I would need to install on the raspberry a software that is only currently provided as source code in .cpp format. As far as I understand I would need to first compile and then run it, however I was able to get any executables that I could automatically run at startup.

Could I ask you to compile that thing for me please? Thanks a lot and excuse my dumbness concerning Linux environment!

Cheers.

Source code: https://github.com/UnexplodedMinds/Rosco2Garmin

bzt
Posts: 564
Joined: Sat Oct 14, 2017 9:57 pm

Re: Help with compiling source

Sat Feb 02, 2019 12:03 pm

Hi,

First, you'll need the libraries that your project depends on. There are usually two packages for each, a "libX" and a "libX-dev". First one required in run-time (contains the shared object binary), and the second one contains the C header files which you'll need for compilation.

Then, you will need the linker (binutils package), the compiler (gcc) and compilation environment (make), but those are usually preinstalled. Some projects also require scripts to generate the compilation environment files (automake, autoconf), but that depends on the project.

Then, you'll have to issue the following three commands in the source directory:

Code: Select all

./configure
This will generate the Makefile script for your system. It will autodetect libraries and check for dependencies. You can tweek the configuration too, use "--help" to get the available arguments. They are in the form "--enable-(feature)" and "--disable-(feature)" or sometimes "--with-(feature)" and "--without-(feature)". For most projects, this configure script is part of the autoconf utilily, so it is advisable to have that installed.

Code: Select all

make
Once your Makefile script is generated, you can use the make command (which will call the compiler and the linker) to do the actual compilation. This usually works just as-is, but in some cases it may fail. If that happens, you should read the output carefully, and install more packages (for example if the error message reads as "sdl.h not found", then you should install the "libsdl-dev" package). The purpose of "./configure" script is to minimize these errors, and make should run without problems.

Code: Select all

sudo make install
Finally, when the compilation is ready, you can install your project with this command. It is important to call it as superuser, because it will copy files under "/usr/bin", "/usr/share", "/var/lib" etc., not writable by default user. If not instructed otherwise with ./configure arguments, the default is to copy the executable into "/usr/local/bin", so you should add that to your PATH if not added already.

Keep in mind, that this is just a generic description which works most of the time, but you always should read the project's README on how to compile that particular project to be sure.

Now according to your project, it has a project file which suggest that you'll need QtCreator to compile. This is a bad practice, sources to be compiled under Linux should follow the "configure+make+make install" path.

Cheers,
bzt

Heater
Posts: 16092
Joined: Tue Jul 17, 2012 3:02 pm

Re: Help with compiling source

Sat Feb 02, 2019 3:29 pm

As bzt says Rosco2Garmin is a Qt project. As such none of his directions will work at all.

A Qt project uses the Qt graphical user interface toolkit and has it's own project file and build system. This is not in anyway "bad practice". Qt is intended to build cross-platform applications that run on Mac, Window, Linux and many other places. It has it's own build system to make that possible.

Here is the steps you need to take to make the Rosco2Garmin program on a Raspberry Pi. It's very easy when it works but see below:

1) Install the required Qt development packages (I'm not sure if all these are required it's just what I did here to get the Qt project file working):

Code: Select all

$ sudo apt-get install qtbase5-dev
$ sudo apt-get install qt5-default
$ sudo apt-get install libqt5websockets5-dev
$ sudo apt-get install libqt5network5
$ sudo apt-get install git
2) Check you have the correct version of Qt. This project requires at least Qt 5.8:

Code: Select all

$ qmake -v
3) Obtain a copy of the source code. It is in a "git" repository so use git to get it like so:

Code: Select all

$ git clone https://github.com/UnexplodedMinds/Rosco2Garmin.git
4) Change into the new directory the above command created:

Code: Select all

$ cd Rosco2Garmin
5) Use "qmake" to create the required Makefile from the project file:

Code: Select all

$ qmake -o Makefile Rosco2Garmin.pro
6) Use the new Makefile to build the project:

Code: Select all

$ make
...
Translator.cpp:8:28: fatal error: QNetworkDatagram: No such file or directory

                            ^
compilation terminated.
Makefile:346: recipe for target 'Translator.o' failed
make: *** [Translator.o] Error 1
Sadly as you see this build fails on my Pi. I only have Qt version 5.7.1.

However I'm not running Raspbian and I don't know what Qt version that is up to. You will just have to try the above.

Let us know what happens and we can think about how to proceed from there.
Memory in C++ is a leaky abstraction .

Colmoschin94
Posts: 2
Joined: Fri Feb 01, 2019 3:29 pm

Re: Help with compiling source

Sat Feb 02, 2019 5:45 pm

Heater wrote:
Sat Feb 02, 2019 3:29 pm
As bzt says Rosco2Garmin is a Qt project. As such none of his directions will work at all.

A Qt project uses the Qt graphical user interface toolkit and has it's own project file and build system. This is not in anyway "bad practice". Qt is intended to build cross-platform applications that run on Mac, Window, Linux and many other places. It has it's own build system to make that possible.

Here is the steps you need to take to make the Rosco2Garmin program on a Raspberry Pi. It's very easy when it works but see below:

1) Install the required Qt development packages (I'm not sure if all these are required it's just what I did here to get the Qt project file working):

Code: Select all

$ sudo apt-get install qtbase5-dev
$ sudo apt-get install qt5-default
$ sudo apt-get install libqt5websockets5-dev
$ sudo apt-get install libqt5network5
$ sudo apt-get install git
2) Check you have the correct version of Qt. This project requires at least Qt 5.8:

Code: Select all

$ qmake -v
3) Obtain a copy of the source code. It is in a "git" repository so use git to get it like so:

Code: Select all

$ git clone https://github.com/UnexplodedMinds/Rosco2Garmin.git
4) Change into the new directory the above command created:

Code: Select all

$ cd Rosco2Garmin
5) Use "qmake" to create the required Makefile from the project file:

Code: Select all

$ qmake -o Makefile Rosco2Garmin.pro
6) Use the new Makefile to build the project:

Code: Select all

$ make
...
Translator.cpp:8:28: fatal error: QNetworkDatagram: No such file or directory

                            ^
compilation terminated.
Makefile:346: recipe for target 'Translator.o' failed
make: *** [Translator.o] Error 1
Sadly as you see this build fails on my Pi. I only have Qt version 5.7.1.

However I'm not running Raspbian and I don't know what Qt version that is up to. You will just have to try the above.

Let us know what happens and we can think about how to proceed from there.

Ok Cool, I will try to compile the source during the weekend, I will first need to install Raspbian on a new sd since I do not want to use the one I take with me during flights. I will then have to figure out how to export the compiled source to the main SD image I use, but let's do one thing at the time.
Thanks to everyone really, you've all been incredibly kind!

Heater
Posts: 16092
Joined: Tue Jul 17, 2012 3:02 pm

Re: Help with compiling source

Sat Feb 02, 2019 6:03 pm

I'm worried this will not work on Raspbian. As far as I can tell the latest Qt for Raspbian is 5.7.1. This project requires new features in 5.8.

There are two solutions to this. Neither very satisfactory:

1) Download and build Qt 5.8. I suspect this might be a big job that is complex enough you won't want to tackle it. It also takes a long time.

2) Use a Linux distribution on your Pi that does have Qt 5.8 or newer.
Memory in C++ is a leaky abstraction .

bzt
Posts: 564
Joined: Sat Oct 14, 2017 9:57 pm

Re: Help with compiling source

Mon Feb 04, 2019 12:13 am

Heater wrote:
Sat Feb 02, 2019 6:03 pm
I'm worried this will not work on Raspbian. As far as I can tell the latest Qt for Raspbian is 5.7.1. This project requires new features in 5.8.

There are two solutions to this. Neither very satisfactory
...and this is exactly why I consider qmake and similar build-systems a bad practice :-) Makefile scripts are compatible regardless to make's version, and thanks to ./configure, it is a pretty much compiler and linker version agnostic solution too. Just for the records, I had no problems using ./configure+make on Raspbian, x86 Linux, BSDs, MacOSX and Windows (with cygwin and mingw).
I will then have to figure out how to export the compiled source to the main SD image I use, but let's do one thing at the time.
Since there are not much data files, I assume simply copying the linked executable will suffice.

Cheers,
bzt

Heater
Posts: 16092
Joined: Tue Jul 17, 2012 3:02 pm

Re: Help with compiling source

Mon Feb 04, 2019 12:48 am

bzt,
...and this is exactly why I consider qmake and similar build-systems a bad practice :-) Makefile scripts are compatible regardless to make's version,...
I don't see the problem. qmake generates a Makefile. It can also do what is required to get the project built for MS Visual C++ on Windows or build Android/iOS aps etc. It can also build for embedded targets that don't have an OS. ./configure cannot do all this.
...thanks to ./configure, it is a pretty much compiler and linker version agnostic solution too. Just for the records, I had no problems using ./configure+make on Raspbian, x86 Linux, BSDs, MacOSX and Windows (with cygwin and mingw).
Are you saying you have built Qt apps using ./configure+make? I did not know this was possible and would love to hear how you do it.

Anyway, the problem here is not with qmake or any build system. The problem is that the Rosco2Garmin source makes use of a Qt class called "QtNetworkDatagram" which was introduced into Qt at version 5.8. As far as I can tell Raspbian/Debian only has Qt 5.7.1.

No amount of ./configure+make would fix the fact that you don't have up to date libraries installed.

I suggest contacting the author, perhaps by posting ab issue on the project's github repository.

As it happens one can build Qt5 from sources on a Pi to get the latest version: https://wiki.qt.io/Native_Build_of_Qt5_ ... spberry_Pi I did this a while back to get Qt version 4. It was a lot of effort and took many hours. It's probably a lot quicker and easier on a Pi 3 B now a days but I have not tried yet.

You will be pleased to hear that building the Qt libraries uses ./configure :)
Memory in C++ is a leaky abstraction .

bzt
Posts: 564
Joined: Sat Oct 14, 2017 9:57 pm

Re: Help with compiling source

Mon Feb 04, 2019 11:16 am

Heater wrote:
Mon Feb 04, 2019 12:48 am
Are you saying you have built Qt apps using ./configure+make? I did not know this was possible and would love to hear how you do it.
Sure, linking an application with Qt requires some C/C++ header files and a (shared) library. Configure (or any other build-system) can detect those, just like any other library dependency.
No amount of ./configure+make would fix the fact that you don't have up to date libraries installed.
My apologies, you're perfectly right about that. My first reading was a newer Qt Creator was required. My mistake.
You will be pleased to hear that building the Qt libraries uses ./configure :)
Be my guest :-) Naturally building the Qt library itself uses ./configure+make (because it's going to compile qmake too, which is a part of qt-base).

For an application example, the vlc Qt frontend does not use Qt Creator (nor configure as a matter of fact), it collects the required gcc flags using cmake for example: vlc-qt.

Cheers,
bzt

Heater
Posts: 16092
Joined: Tue Jul 17, 2012 3:02 pm

Re: Help with compiling source

Mon Feb 04, 2019 1:00 pm

There are many ways to build things.

Have you really, actually, created a Qt project that is built with ./configure. I would really like to hear how you did it.

cmake is great and all. But setting it up in the first place is a pain.

Much easier to use qmake which comes straight out of the box.

Don't forget Qt comes from a time and a place where cmake did not exist and auto tools were not a thing. qmake was first !
Memory in C++ is a leaky abstraction .

bzt
Posts: 564
Joined: Sat Oct 14, 2017 9:57 pm

Re: Help with compiling source

Tue Feb 05, 2019 12:09 pm

Heater wrote:
Mon Feb 04, 2019 1:00 pm
Don't forget Qt comes from a time and a place where cmake did not exist and auto tools were not a thing. qmake was first !
Are you sure? The configure script first appeared in GNU in 1991. The first public realase of Qt was in 1995. Not that it matters.

Sorry, we turned away a bit from the OP's original question. Mea culpa.
bzt

Return to “C/C++”