2

I have installed G++ 4.8 with the C++11 standard.

Searching around the internet I found some flags that apparently should decrease compile time considerably. I have ended with this, it compiles fine but not sure if its entirely correct.

-std=c++0x -Ofast -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard 

I am no G++/C++ expert and was wondering if there is anything I should change with that to get better compile performance on the Pi 2 or if there are any caveats I have not run into yet by using these arguments.

  • 1
    Those flags are unlikely to make any difference to compile times or anything else, since the compiler is already optimized for the native platform (meaning they're pointless)-- something you can test for yourself, at least WRT compile times. They tend to be propagated by OCD and/or cargo cult types, I think. They probably won't do any harm though. -Ofast may make a difference but it comes with some caveats -- see man gcc. Generally in development you want -O0 to ensure that values are not optimized out when debugging. The default is I think -O2. – goldilocks Jun 8 '15 at 22:14
  • 1
    An exception to this might be if you are using an ARMv6 userland (i.e., with an ARMv6 g++), which is possible on the Pi 2 but would be slower than a dedicated ARMv7 userland. However, since the libc is then ARMv6, I'm not sure how much advantage you'll really get, presuming the compiler is capable of it in the first place. That's a more complex question qualified with "when using raspbian on the pi 2", since there is no ARMv7 raspbian -- but if you are new to C++ you are wasting your time being concerned with these kinds of subtleties. – goldilocks Jun 8 '15 at 22:35
  • 1
    I'm guessing there's some serious templating in those boost headers which would account for this -- i.e., you're really compiling a lot more than just those 100 lines. That is an unfortunate thing about C++ and generics. – goldilocks Jun 9 '15 at 10:33
  • 1
    You don't have to be using the boost stuff there, no. I'm not seeing the significance of the ptree thing at all, part of it seems to be about writing json data out to a temp file ??? Those boost headers pull in a bunch more boost headers. WRT using standard C++11, I don't find it slower to compile than old code. c++0x is the same as c++11 for compilers that support the latter; some < 4.7 gcc's only support the former, which was basically the 2011 standard before it was finalized. – goldilocks Jun 9 '15 at 10:51
  • 1
1

On the Pi2 one easy enhancement is to add -j4 to make use of the four cores.


As goldilocks points out the above won't help with a single compilation. -j is an option to make and will only be useful if the make can be broken into multiple jobs.

  • Hi Joan. Please excuse my ignorance.. but will that -j4 apply to the G++ compiler? I am just learning about C++ thanks to the Pi. And not sure how make and g++-4.8 relate to each other. I mean, I don't have to use make if I just use g++-4.8 source.cpp but make executes g++-4.8 source.cpp for me. – Piotr Kula Jun 8 '15 at 19:53
  • 1
    @ppumkin I believe so. They are all part of the gcc (GNU Compiler Collection) suite and a lot of the options will be common to all languages. – joan Jun 8 '15 at 20:18
  • -j4 is a make option and make is not part of GCC. Make, which is about building multiple objects, can run in parallel; a C/C++ compiler, which is about building one object at a time, does not. If you run make with -j, it will potentially spawn multiple concurrent instances of the compiler. Using -j4 with make is certainly more useful than bothering with most of the "optimizing" switches in ppumkin's question if make serves a useful purpose (because multiple discrete compilation units are involved). – goldilocks Jun 8 '15 at 22:20
  • As I suspected. I only got 1 file to compile. It takes way too long to compile as it's not very big or complex. But as I mentioned it may be c++11 std making it take long to compile. – Piotr Kula Jun 9 '15 at 7:03
  • @ppumkin Yes, sorry about that, my mistake. Is it a first time through thing? I have noticed that the first compile after boot is a lot longer than subsequent ones (caching I guess). – joan Jun 9 '15 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.