Would switching to C++ 11 be something to consider ?

42 views
Skip to first unread message

Henner Zeller

unread,
Jul 20, 2016, 11:33:23 AM7/20/16
to beagleg-dev
Hi,
Just a quick check: what is the compiler version you are running
currently ? Newer compilers can compile C++11 which has some smallish
but neat features; e.g. for-loops over containers can be made look
nicer, overrides of virtual method can be described explicitly or some
intialization of test-vectors in unit-tests can be made more readable.
In the end it boils down to have some things more readable.

So far, I have kept the code at C++03 as my previous version of the
BeagleBone Linux was only doing that. Also, in embedded systems, there
are typically a lot of reasons to switch versions more slowly, so I am
wondering if this might be a problem or are you guys fine with doing
the jump ?

-h

Hartley Sweeten

unread,
Jul 20, 2016, 2:53:54 PM7/20/16
to beagleg-dev, h.ze...@acm.org
Hi,
I have a couple setups.

This is my main developemnt system right now
$ cat /etc/issue
Debian GNU/Linux 7
$ g++ --version
g++ (Debian 4.7.2-5) 4.7.2

I will be moving to this development system eventually
$ cat /etc/issue
Debian GNU/Linux stretch/sid
$ g++ --version
g++ (Debian 5.4.0-3) 5.4.0.2016003

My Beaglebone currently has this:
$ cat /etc/issue
Debian GNU/Linux 7
BeagleBoard.org Debian Image 2015-03-01
$ g++ --version
g++ (Debian 4.6.3-14) 4.6.3

But, I am thinking of trying out the latest image from BeagleBone.org.
It's Debian 8 but I'm not sure what the g++ version is.

I don't have any problem with changing to C++11 but I don't know what
versions of g++ support it.

Hartley

Leonardo Romor

unread,
Jul 20, 2016, 4:37:31 PM7/20/16
to beagleg-dev, h.ze...@acm.org
Hi,

I'm fine with the jump, we recently switched to debian 8 and kernel 4.4 bone line,  
Right now I cannot check che exact version but I'm pretty sure it's ~4.9.2 (debian jessie default one).
regarding c++11:
GCC 4.8.1 was the first feature-complete implementation of the 2011 C++ standard, previously known as C++0x.
 
We should add a bunch of lines in the readme describing on how people should install the bone line kernel because the default debian jessie installation
has the ti kernel which is without uio_pruss. Maybe providing a script or a web reference to make the update.

-l

Henner Zeller

unread,
Sep 20, 2016, 3:21:55 AM9/20/16
to Leonardo Romor, Hartley Sweeten, beagleg-dev
Alright, I think we should be switching to c++11, which brings us more
readable loops for instance
for (int foo : int_container) { ... }

The oldest mentioned compiler 4.6.3 on one of Hartley's machines
should already be able to deal with it, but it might need -std=c++0x.
Looking on my current BeagleBone, there is a g++ 4.9.1 compiler on it.

We have a fairly limited platform at this point (Linux based, fairly
new distributions available) which allows us the assumption that we
can get a fairly recent compiler; we don't want to be able to
cross-compile on some 20 year old platform etc. and it would be silly
to avoid the more modern language features.
C++11 standard already is surpassed by C++14 and C++17 is essentially
in the final steps to be ratified ( https://isocpp.org/std/status ).
So being on a 6 year old standard is not too crazy of an requirement.

However, it seems that things are even slower to compile on a
BeagleBone black now. From a clean state (ccache cleaned) and running
'make test', it now takes about 7-ish minutes for a 'make test', while
previously it was like 6:30min or so (in particular the tests compile
forever). After that, with ccache, everything is a few seconds (except
things that changed).

Well, usually we compile and test on a regular machine, and even on my
2012 laptop with a clean ccache the whole compilation and testing of
the whole project only takes 16 seconds. I hope everyone who wants to
get into Development has read the development page that explicitly
points out to not do development on the BeagleBone and also suggests
to install ccache.

Please try it out and tell me if there are any issues.
Leonardo, would you like to prepare a patch to the README that
describes that ? Maybe we need to put that in the "Build" section
(probably to be called "Install" then) in the toplevel Readme.

Cheers,
Henner.

>
> -l
>
> --
> You received this message because you are subscribed to the Google Groups
> "beagleg-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to beagleg-dev...@googlegroups.com.
> To post to this group, send email to beagl...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/beagleg-dev/98c76491-eaf8-41bb-bc25-06686e35c1b1%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Leonardo Romor

unread,
Sep 20, 2016, 4:28:31 AM9/20/16
to beagleg-dev, leonard...@gmail.com, Hart...@visionengravers.com, h.ze...@acm.org
Yes! I will prepare it this evening.

-l

Hartley Sweeten

unread,
Sep 20, 2016, 12:56:04 PM9/20/16
to Henner Zeller, Leonardo Romor, beagleg-dev
On Tuesday, September 20, 2016 12:22 AM, Henner Zeller wrote:
> Alright, I think we should be switching to c++11, which brings us more
> readable loops for instance
> for (int foo : int_container) { ... }
>
> The oldest mentioned compiler 4.6.3 on one of Hartley's machines
> should already be able to deal with it, but it might need -std=c++0x.
> Looking on my current BeagleBone, there is a g++ 4.9.1 compiler on it.

The BeagleBoard.org Debian Image 2015-03-01 (which is what I think the
BeagleBone Black Rev. C ships with) has 4.6.3. I will test the latest HEAD
later today to make sure it compiles and runs fine on that image.

One of my Debian host machines (Debian 7.11) has 4.7.2 on it. The latest
HEAD compiles fine on that machine and passes all the tests.

My other Debian host machines are all newer releases (Debian 8 or sid)
so I don't think there are any issues with them.

> We have a fairly limited platform at this point (Linux based, fairly
> new distributions available) which allows us the assumption that we
> can get a fairly recent compiler; we don't want to be able to
> cross-compile on some 20 year old platform etc. and it would be silly
> to avoid the more modern language features.
> C++11 standard already is surpassed by C++14 and C++17 is essentially
> in the final steps to be ratified ( https://isocpp.org/std/status ).
> So being on a 6 year old standard is not too crazy of an requirement.

I agree. As long as beagleg compiles on the BeagleBone itself with
whatever its default image is I don't think we need to worry about
someone trying to run it on an older image(Angstrom? Ugh).

> However, it seems that things are even slower to compile on a
> BeagleBone black now. From a clean state (ccache cleaned) and running
> 'make test', it now takes about 7-ish minutes for a 'make test', while
> previously it was like 6:30min or so (in particular the tests compile
> forever). After that, with ccache, everything is a few seconds (except
> things that changed).
>
> Well, usually we compile and test on a regular machine, and even on my
> 2012 laptop with a clean ccache the whole compilation and testing of
> the whole project only takes 16 seconds. I hope everyone who wants to
> get into Development has read the development page that explicitly
> points out to not do development on the BeagleBone and also suggests
> to install ccache.

Have you tried to cross-compile beagle on your host machine and then
just copy machine-control to the BeagleBone? I still need to setup that
and try it. Hopefully it works because I have another app that I need to
compile for the BeagleBone and it takes 15-20 minutes when compiled
there. I have additional dependencies with that app (SDL among them)
so I haven't went down that rabbit hole to figure out the cross-compile
issues....

If you have tried cross-compiling, what compiler have you used and do
you have a link?

Regards,
Hartley

Hartley Sweeten

unread,
Sep 20, 2016, 1:17:52 PM9/20/16
to Hartley Sweeten, Henner Zeller, Leonardo Romor, beagleg-dev
On Tuesday, September 20, 2016 9:56 AM, Hartley Sweeten wrote:

The bone-debian-7.11-lxde-4gb-armhf-2016-06-16-4gb.img doesn't work.
This is from a clean image on the SD-card:

$ cat /etc/dogtag
BeagleBoard.org Debian Image 2016-06-15

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 7.11 (wheezy)
Release: 7.11
Codename: wheezy

$ gcc --version
gcc (Debian 4.6.3-14) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ make BEAGLEG_HARDWARE_TARGET=VGEN5
make -e -C src all
make[1]: Entering directory `/home/debian/repo/beagleg/src'
g++ -std=c++11 -Wall -I../am335x_pru_package/pru_sw/app_loader/include -I../hardware/VGEN5 -D_XOPEN_SOURCE=500 -mtune=cortex-a8 -march=armv7-a -O3 -DCAPE_NAME='"VGEN5"' -c machine-control.cc -o machine-control.o
cc1plus: error: unrecognized command line option ‘-std=c++11’
make[1]: *** [machine-control.o] Error 1
make[1]: Leaving directory `/home/debian/repo/beagleg/src'
make: *** [all] Error 2

Bummer....
Hartley

Hartley Sweeten

unread,
Sep 20, 2016, 1:24:28 PM9/20/16
to Henner Zeller, Leonardo Romor, beagleg-dev
On Tuesday, September 20, 2016 10:18 AM, Hartley Sweeten wrote:
> On Tuesday, September 20, 2016 9:56 AM, Hartley Sweeten wrote:
>
>The bone-debian-7.11-lxde-4gb-armhf-2016-06-16-4gb.img doesn't work.

Update. -std-c++0x does compile and machine-control seems to work fine.

Hartley

Henner Zeller

unread,
Sep 21, 2016, 12:19:18 AM9/21/16
to Hartley Sweeten, Leonardo Romor, beagleg-dev
On 20 September 2016 at 10:24, Hartley Sweeten
Alright, so I updated the Makefile to use this C++ standard name. The
newer compilers also understand this earlier working name of the
standard, so this seems to be fine. Looks like because Debian 7.11 is
a 'long term support' version, that they still have the ancient
compiler.

(The image I have on my Beaglebeone is a Debian GNU/Linux 8 (jessie)
and it comes with a gcc 4..9.2)

Cheers,
Henner.

>
> Hartley
>
> --
> You received this message because you are subscribed to the Google Groups "beagleg-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to beagleg-dev...@googlegroups.com.
> To post to this group, send email to beagl...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/beagleg-dev/BLUPR0101MB1554A33193B3BF5BE7E07A38D0F70%40BLUPR0101MB1554.prod.exchangelabs.com.

Henner Zeller

unread,
Sep 21, 2016, 2:21:13 AM9/21/16
to Hartley Sweeten, beagleg-dev
On 20 September 2016 at 22:15, Hartley Sweeten <biggu...@gmail.com> wrote:
> On Tue, Sep 20, 2016 at 9:19 PM, Henner Zeller <h.ze...@acm.org> wrote:
>>
>> On 20 September 2016 at 10:24, Hartley Sweeten wrote:
>> > On Tuesday, September 20, 2016 10:18 AM, Hartley Sweeten wrote:
>> >> On Tuesday, September 20, 2016 9:56 AM, Hartley Sweeten wrote:
>> >>
>> >>The bone-debian-7.11-lxde-4gb-armhf-2016-06-16-4gb.img doesn't work.
>> >
>> > Update. -std-c++0x does compile and machine-control seems to work fine.
>>
>> Alright, so I updated the Makefile to use this C++ standard name. The
>> newer compilers also understand this earlier working name of the
>> standard, so this seems to be fine. Looks like because Debian 7.11 is
>> a 'long term support' version, that they still have the ancient
>> compiler.
>
>
> Sounds good. I think having BeagleG work on the long term support image
> is a good idea.
>
> One thing I forgot to check is if there is also a gcc 4.7 (or later) package
> also
> available in that image. I'll check tomorrow. If there is we could just note
> it
> in BeagleG and require that compiler (with -std-c++11).
>
> Are there any limitations with -std-c++0x vs. -std-c++11?

There are several features in the c++11 standard and the earlier
compiler versions might not have implemented all of them. The main
reason why things were called 0x then was, because it was not clear
yet what the final version would be named (and they apparently
expected it to be in the 0x years, but it became 1x).
So there might not all features be fully implemented yet, though the
bulk of the interesting features are.

Here is an overview
https://gcc.gnu.org/projects/cxx-status.html#cxx11
The bulk of the features (some quite interesting ones, such as 'auto'
and range-for loops) seemed to have been there since 4.4 already.

Some features, such as delegating constructors, we have to avoid for
now, but that is not a big deal.

It is a bit unfortunate that it seems that the 'override' keyword only
appears in 4.7 it seems. It is a great way to explicitly tell the
compiler that a particular method with a particular signature is meant
to be overriding some base class. This is great when there are changes
in the gcode parser callbacks for instance.

> Regardless, I
> guess
> we can only use the features that work with the 4.6 compiler in wheezy if
> it's
> the only one available.

Yep

>
>>
>> (The image I have on my Beaglebeone is a Debian GNU/Linux 8 (jessie)
>> and it comes with a gcc 4..9.2)
>
>
> I was trying to switch my system to the jessie image but ran into a
> problem....
>
> My cape uses one of the HDMI audio pins (P9_25 I think). I also need the
> HDMI
> video and eMMC, so unfortunately I can't move that signal because I'm using
> all
> the other non-HDMI/eMMC pins already.
>
> With the wheezy images this isn't a problem. The "HDMIN" overlay gets the
> video
> and eMMC working and the cape-universal overlay gives me all the other
> signals
> that I need for my cape.
>
> The latest jessie images appear to work a bit differently. The HDMI and eMMC
> support is loaded in the initial dtb when the system boots. It then loads
> the appropriate
> cape-universal overlay to allow access to the remaining pins. According to
> Robert
> Nelson the "HDMIN" equivalent from wheezy is not currently available in
> jessie. I
> guess he had some problems with the eMMC support. Hopefully he works it out
> at
> some point.

mmh, hopefully this is not too big of a problem. It sounds like a
problem that might be fixed soon in the jessie image.

>
> Since I'm using the cape-universal overlay for my VGEN5 hardware, I would
> prefer
> to use the jessie image since it gets everything pretty much ready during
> the boot.
> Oh well...
>
> Regards,
> Hartley

Hartley Sweeten

unread,
Sep 21, 2016, 2:31:00 PM9/21/16
to Henner Zeller, Hartley Sweeten, beagleg-dev
On September 20, 2016 11:21 PM, Henner Zeller wrote:
> On 20 September 2016 at 22:15, Hartley Sweeten <biggu...@gmail.com> wrote:
>> On Tue, Sep 20, 2016 at 9:19 PM, Henner Zeller <h.ze...@acm.org> wrote:
>>> Alright, so I updated the Makefile to use this C++ standard name. The
>>> newer compilers also understand this earlier working name of the
>>> standard, so this seems to be fine. Looks like because Debian 7.11 is
>>> a 'long term support' version, that they still have the ancient
>>> compiler.
>>
>>
>> Sounds good. I think having BeagleG work on the long term support image
>> is a good idea.
>>
>> One thing I forgot to check is if there is also a gcc 4.7 (or later) package
>> also available in that image. I'll check tomorrow. If there is we could just
>> note it in BeagleG and require that compiler (with -std-c++11).

Henner,

It appears that gcc-4.7 is available in the wheezy image. I'm in the process
of installing it now to see if the -std-c++11 switch works.

If so maybe we just make one of the beagle requirements be gcc >= 4.7?

If I get the time I'll try to narrow down what the various images have
installed as the default gcc version and what is available.

Hartley

Hartley Sweeten

unread,
Sep 21, 2016, 3:13:45 PM9/21/16
to Hartley Sweeten, Henner Zeller, Hartley Sweeten, beagleg-dev
On Wednesday, September 21, 2016 11:31 AM, Hartley Sweeten wrote:
> It appears that gcc-4.7 is available in the wheezy image. I'm in the process
> of installing it now to see if the -std-c++11 switch works.

OK. That worked with the bone-debian-7.11-lxde-4gb-armhf-2016-06-15-4gb.img:

$ cat /etc/dogtag
BeagleBoard.org Debian Image 2016-06-15
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 7.11 (wheezy)
Release: 7.11
Codename: wheezy
$ uname -a
Linux beaglebone 3.8.13-bone80 #1 SMP Wed Jun 15 17:03:55 UTC 2016 armv7l GNU/Linux

$ sudo apt-get install gcc-4.7 g++4.7
...
$ g++-4.7 --version
g++-4.7 (Debian 4.7.2-5) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ git reset --hard HEAD
HEAD is now at ca1692a o Work thinning out gcode-parser.cc. Move save/load params
$ make BEAGLEG_HARDWARE_TARGET=VGEN5 CXX=g++-4.7
make -e -C src all
make[1]: Entering directory `/home/debian/repo/beagleg/src'
...
make[1]: Leaving directory `/home/debian/repo/beagleg/src'
$

No errors/warnings and machine-control works.

Hartley

Henner Zeller

unread,
Sep 22, 2016, 2:03:07 PM9/22/16
to beagleg-dev, Hartley Sweeten, Leonardo Romor
On 21 September 2016 at 12:13, Hartley Sweeten
That is good; so even on the 'older' debian, it would be possible to
get a compiler that can deal at least with 'override' which might be
some readability improvement. Alas, we would need to explicitly tell
people to say CXX=g++-4.7 or have a configure-script (which I really
would like to avoid).

I'll install the debian image you mentioned and play around a little.

In the latest submit
https://github.com/hzeller/beagleg/commit/3baea61e37b337ff79d800fd8e8140e11ef2b521
I am using another C++ feature and replaced some uses of a raw C
function pointer with C++ std::function<> and instances of it with
lambdas which greatly increases readability for these. Hopefully these
will still work on gcc 4.6.3 (according to the release notes, this
should be available since 4.5).

Cheers,
Henner.

>
> Hartley
>
> --
> You received this message because you are subscribed to the Google Groups "beagleg-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to beagleg-dev...@googlegroups.com.
> To post to this group, send email to beagl...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/beagleg-dev/SN1PR0101MB1565C14B3A7063B612D46DB0D0F60%40SN1PR0101MB1565.prod.exchangelabs.com.
Reply all
Reply to author
Forward
0 new messages