nick8967
Posts: 114
Joined: Fri Mar 25, 2016 11:02 pm

Running C/C++ on Raspberry Pi

Wed Oct 02, 2019 7:19 am

Hello,

I want to write code on C/C++ on Rpi 3 B+. Is there any reliable IDE to help me on that? Is C/C++ officially supported (as python) by Rpi or I should do "tricks" and result in doing nothing? Of course I will use libraries on C/C++ so I search for a "mainstream" solution...

Any suggestion?

Thank you

jahboater
Posts: 4846
Joined: Wed Feb 04, 2015 6:38 pm

Re: Running C/C++ on Raspberry Pi

Wed Oct 02, 2019 7:53 am

nick8967 wrote:
Wed Oct 02, 2019 7:19 am
or I should do "tricks" and result in doing nothing?
Interesting to know what these "tricks" are ?

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

Re: Running C/C++ on Raspberry Pi

Wed Oct 02, 2019 7:54 am

The Pi runs Raspbian which includes GCC, The GNU Compiler Collection, which compiles C and C++ among other languages. You cannot get more mainstream than GCC.

I try to avoid using IDE's but Microsoft's Visual Studio Code is a greate whiich supports pretty much anything you need from an IDE with extensions. VS Code is open source and runs on Linux, Mac and Windows. I hear it runs on the Pi as well.
Memory in C++ is a leaky abstraction .

nick8967
Posts: 114
Joined: Fri Mar 25, 2016 11:02 pm

Re: Running C/C++ on Raspberry Pi

Wed Oct 02, 2019 8:40 am

The best optimization I can get is with gcc or with Visual Studio?

Thanks

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

Re: Running C/C++ on Raspberry Pi

Wed Oct 02, 2019 9:45 am

Your question makes no sense gcc is a compiler, Visual Studio is an IDE.

As as far as I know MicroSoft's compiler MSVCC cannot generate code to run on a Pi using Raspbian.

GCC is a high quality, industry standard C/C++ compiler with very good optimizatiion.

Almost certainly the code you write will have more effect on performance than any difference between compilers.
Memory in C++ is a leaky abstraction .

markkuk
Posts: 137
Joined: Thu Mar 22, 2018 1:02 pm
Location: Finland

Re: Running C/C++ on Raspberry Pi

Wed Oct 02, 2019 10:29 am

nick8967 wrote:
Wed Oct 02, 2019 8:40 am
The best optimization I can get is with gcc or with Visual Studio?
Visual Studio Code is a completely different program from Visual Studio. Visual Studio Code is a cross-platform code editor with plugins that enable IDE-like properties. It doesn't include a compiler for any language. If you write C or C++ with VSCode you need to use GCC or Clang as the compiler.

jahboater
Posts: 4846
Joined: Wed Feb 04, 2015 6:38 pm

Re: Running C/C++ on Raspberry Pi

Wed Oct 02, 2019 10:36 am

nick8967 wrote:
Wed Oct 02, 2019 8:40 am
The best optimization I can get is with gcc or with Visual Studio?
GCC is pre-installed and ready to use.
Clang is an alternative that may be installed if desired.

The optimization done by GCC is class leading.
You can easily examine the assembler code emitted. If you are familiar with assembler, you will likely be very surprised how clever the compiler is.

GCC on the Pi supports many languages:
C, Ada, C++, Go, D, Fortran, Objective C, Objective-C++

GCC also has full support for the latest language standards such as C18 and C++17, which MSVC will never have.

GCC is considered by many to be the gold standard.

In summary, I suggest just use GCC, it will do everything you want and more.

nick8967
Posts: 114
Joined: Fri Mar 25, 2016 11:02 pm

Re: Running C/C++ on Raspberry Pi

Wed Oct 02, 2019 11:41 am

Sorry, but objective C/C++ doesn't run only on macbooks??

User avatar
PeterO
Posts: 5156
Joined: Sun Jul 22, 2012 4:14 pm

Re: Running C/C++ on Raspberry Pi

Wed Oct 02, 2019 11:54 am

nick8967 wrote:
Wed Oct 02, 2019 11:41 am
Sorry, but objective C/C++ doesn't run only on macbooks??
I can't tell if that is that a statement or a question.
But....
Objective-C will run on lots of platforms.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
B.Goode
Posts: 8987
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Running C/C++ on Raspberry Pi

Wed Oct 02, 2019 11:57 am

nick8967 wrote:
Wed Oct 02, 2019 11:41 am
Sorry, but objective C/C++ doesn't run only on macbooks??

https://gcc.gnu.org/onlinedocs/gcc/Obje ... tions.html

Note that the poster didn't make any claim about that being a useful option on a Raspberry Pi, only that it was a feature of the GCC compiler.

dsyleixa123
Posts: 462
Joined: Mon Jun 11, 2018 11:22 am

Re: Running C/C++ on Raspberry Pi

Wed Oct 02, 2019 12:53 pm

nick8967 wrote:
Wed Oct 02, 2019 7:19 am
Hello,

I want to write code on C/C++ on Rpi 3 B+. Is there any reliable IDE to help me on that? Is C/C++ officially supported (as python) by Rpi or I should do "tricks" and result in doing nothing? Of course I will use libraries on C/C++ so I search for a "mainstream" solution...

Any suggestion?

Thank you
a IDE for compilers to C (gcc) and C++ (g++) is the IDE Geany, it's easy, simple, handy, and already pre-installed.
Grafic IDEs (GUI-IDEs) like Visual Studio for Windows which work for Linux e.g. are qt creator, gtk, openCV - but for a beginner they are real monsters...

A tutorial for C/C++ using Geany e.g. is this one: http://fractal.math.unr.edu/~ejolson/pi ... dified.pdf

(note that you can build and run the executables directly out of Geany (internally), or instead do that build and run (externally) out of a terminal window).

jachaney
Posts: 13
Joined: Wed Jun 20, 2018 10:00 pm

Re: Running C/C++ on Raspberry Pi

Mon Oct 14, 2019 10:46 pm

If you are on a Raspberry Pi, It is best to use Code:Blocks for an IDE, and start with a simple console application for the "hello, world!" I can be installed easily using
`sudo apt-get install codeblocks`

Look up GTK+ documentation for making GUI based applications. I use the 2.0 version and downloaded the development libraries with `sudo apt-get install libgtk2.0-dev`. Then added `pkg-config --cflags gtk+-2.0` to the include path, and `pkg-config --libs gtk+-2.0` to the additional libraries.

User avatar
HermannSW
Posts: 1658
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Running C/C++ on Raspberry Pi

Tue Oct 15, 2019 12:10 am

My IDE for C/C++ is
  • vi (editor, use it since 1990)
  • gcc/g++ (compiler)
  • gdb (debugger)
  • make
  • (git)
I don't need more than that.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

jahboater
Posts: 4846
Joined: Wed Feb 04, 2015 6:38 pm

Re: Running C/C++ on Raspberry Pi

Tue Oct 15, 2019 12:49 am

HermannSW wrote:
Tue Oct 15, 2019 12:10 am
My IDE for C/C++ is
  • vi (editor, use it since 1990)
  • gcc/g++ (compiler)
  • gdb (debugger)
  • make
  • (git)
I don't need more than that.
+1 !!

Except that I use a home written editor instead of vi.

jachaney
Posts: 13
Joined: Wed Jun 20, 2018 10:00 pm

Re: Running C/C++ on Raspberry Pi

Tue Oct 15, 2019 2:30 am

I too was a "basic text editor" VI coder. Waged battles of VI v. Emacs. Scripting v. compiled. Writing macros, and shortcuts, for common operations. Wrote my own make make. The thing is, if I can use a tool to make my life easier, and get me to the finish line quicker, I will use it. GIT is fashionable these days, but I have used Mercurial for several years, so I am used to it.

I was an early adopter of Eclipse, mostly because I was doing a lot of Java stuff back then. I tried running Eclipse on the Pi, and it does work pretty well, but I ran into some library problems with the new version of VM from Oracle, so I switched over to Code:Blocks. I miss some of the mechanisms that Eclipse had, but the small size and speed make up for it.

Running C/C++ on Raspberry Pi, is no different than running it on any Linux based system, so I was providing the quickest and easiest way to produce code, of non-trivial content. True a single file "hello, world!" can be done fully from the command line with a basic editor, but if the program has a high level of complexity, and uses multiple libraries, an IDE helps keep things orderly.

Jack

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Running C/C++ on Raspberry Pi

Tue Oct 15, 2019 8:24 pm

HermannSW wrote:
Tue Oct 15, 2019 12:10 am
My IDE for C/C++ is
  • vi (editor, use it since 1990)
  • gcc/g++ (compiler)
  • gdb (debugger)
  • make
  • (git)
I don't need more than that.
Same here.
Except, I use cmake because I really don't like Makefiles and cmake takes away that pain.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

dsyleixa123
Posts: 462
Joined: Mon Jun 11, 2018 11:22 am

Re: Running C/C++ on Raspberry Pi

Tue Oct 15, 2019 9:12 pm

vi is really a cumbersome crutch from times when the rock'n'roll was invented and which honestly makes me vomite - instead, Geany is a handsome and reasonable editor and IDE.

jcyr
Posts: 503
Joined: Sun Apr 23, 2017 1:31 pm
Location: Atlanta

Re: Running C/C++ on Raspberry Pi

Tue Oct 15, 2019 11:55 pm

dsyleixa123 wrote:
Tue Oct 15, 2019 9:12 pm
vi is really a cumbersome crutch from times when the rock'n'roll was invented and which honestly makes me vomite - instead, Geany is a handsome and reasonable editor and IDE.
Try running that in an terminal window via SSH.
It's um...uh...well it's kinda like...and it's got a bit of...

User avatar
Paeryn
Posts: 2749
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Running C/C++ on Raspberry Pi

Wed Oct 16, 2019 12:37 am

dsyleixa123 wrote:
Tue Oct 15, 2019 9:12 pm
vi is really a cumbersome crutch from times when the rock'n'roll was invented and which honestly makes me vomite - instead, Geany is a handsome and reasonable editor and IDE.
I somehow doubt the honesty of your said reaction to vi. There's nothing wrong with vi (though vim has replaced vi nowadays) although for some strange reason vim-basic is the default installed version (probably more compatible with the original vi). The first thing I do is uninstall that and install the full-fat vim, there's so much of vim missing in vim-basic that I'm sure vim-basic puts newcomers off.

There's gvim as well for when you want a gui rather than console interface. Then again I've been using vim (and emacs) for over 25 years so I'm used to them.
She who travels light — forgot something.

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

Re: Running C/C++ on Raspberry Pi

Wed Oct 16, 2019 3:55 am

dsyleixa123,

Oh for goodness sake. Rock'n'roll arrived in the early 1950s and even before that. Vi did not arrive til the late 1970s

There are so many situations where a "handsome and reasonable editor and IDE" will not work and is of no use what so ever that is very useful to have vi/vim available. It's not a crutch it's a useful, powerful and often essential tool.

If you took the trouble to find out you will discover that vim can run rings around Geany, for example, in terms of functionality and productivity.

Or were you just trolling? I always fall for it...
Memory in C++ is a leaky abstraction .

User avatar
rpdom
Posts: 15604
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Running C/C++ on Raspberry Pi

Wed Oct 16, 2019 5:26 am

Vi used to be the editor you could depend on being available on pretty much any *nix based system - even in recovery mode.

Although recently I worked on systems that had nano instead of vi. That confused me. I installed a minimal vi as soon as I could on them.

Anyone who is likely to do any sysadmin roles at any point should try to learn just basic vi usage.

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Running C/C++ on Raspberry Pi

Wed Oct 16, 2019 6:31 am

Paeryn wrote:
Wed Oct 16, 2019 12:37 am

The first thing I do is uninstall that and install the full-fat vim, there's so much of vim missing in vim-basic that I'm sure vim-basic puts newcomers off.
Exactly what I do. I'll see if I can lobby the RPF folks (in the same way I did for ntfs-3g) to get that fixed.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

dsyleixa123
Posts: 462
Joined: Mon Jun 11, 2018 11:22 am

Re: Running C/C++ on Raspberry Pi

Wed Oct 16, 2019 7:11 am

haha, I had bet that my post would provoke those answers :D
But for programming I never use terminal windows and neither ssh, for programming on the Pi one would need a mouse, a comfortable File menu, several tabs, colored code highlighting, symbols and docs side bar, auto-intend, check for brackets/nesting levels, compile-error checking and highlighting feat. a jump to either code line a.s.o., compile+build+run out of the IDE, and that is just what Geany is providing.
OTOH, code::blocks does even much more, and actually that is already far too much for beginners and hobby programmers.

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

Re: Running C/C++ on Raspberry Pi

Wed Oct 16, 2019 7:44 am

dsyleixa123,

Well done Sir. Excellent troll.

Meanwhile:
For programming on the Pi one would need a mouse, a comfortable File menu, several tabs, colored code highlighting, symbols and docs side bar, auto-intend, check for brackets/nesting levels, compile-error checking and highlighting feat. a jump to either code line a.s.o., compile+build+run out of the IDE,
Wow, did you say vim was a crutch? How many crutches do you need to make any progress? It's amazing you can even stand up.

As it happens Vim can do all of that.

Damn that nano thing. It turns up everywhere now. Who thought that was good idea?
Memory in C++ is a leaky abstraction .

dsyleixa123
Posts: 462
Joined: Mon Jun 11, 2018 11:22 am

Re: Running C/C++ on Raspberry Pi

Wed Oct 16, 2019 7:57 am

vi with a mouse and colored code highlighting and compile+run out of the program a.s.o...?
If I type vi in the console it's just an ugly b+w text-box.
(ok, nano is surely even worse, actually not even worth mentioning...)

PS,
and don't forget: this topic is about a beginner to C(++) programming on the Pi who is asking about an IDE.
Even the MagPi C tutorial is using Geany.

Return to “C/C++”