Page 1 of 1

Ways to compile C/C++ code for pi

Posted: Tue Aug 13, 2019 11:27 am
by Luka147
I want to buy a raspberry pi soon but before that, I need to know what are the ways to compile code for arm architecture.
If you guys know any ways to do so, thank you in advance.

Re: Ways to compile C/C++ code for pi

Posted: Tue Aug 13, 2019 12:19 pm
by mahjongg
yes of course you can.

here is how:
https://www.youtube.com/watch?v=Rv41Gtn ... lKNsidxfwX

Re: Ways to compile C/C++ code for pi

Posted: Tue Aug 13, 2019 12:30 pm
by jahboater
An excellent C and C++ compiler is included, pre-installed, and ready to use.

Create the usual little test program with any editor in a file called "hello.c"

Code: Select all

#include <stdio.h>

int
main( void )
{
  puts( "hello world!" );
}
Compile it with:

Code: Select all

cc hello.c -o hello
and finally, you can run the program as many times as you like with:

Code: Select all

./hello

Re: Ways to compile C/C++ code for pi

Posted: Tue Aug 13, 2019 12:38 pm
by deepo
I'm not quire sure what it is you're asking for, but the easiest way it to use the Raspbian OS which comes with g++ installed.
If you choose the desktop (not Lite version) you will be able to easily edit and compile C/C++ code on you Raspberry.
It is of course also possible with the console only Lite version, but it is easier to have a window for compiling along with your editor.

The most basic syntax of g++ is:

Code: Select all

g++ -o example example.cpp
For C code you'll need the gcc compiler:

Code: Select all

gcc -o hello main.c
Sorry - I can't remember which compilers are included on the Raspbian OS images. But cc is installed by default, as jahboater writes above.

There are cross compiler options that allow you to do everything on e.g. Windows and then transfer the executable to the Raspberry Pi. But I haven't used them. I think JetBrains can do that with their IDE CLion.

/Mogens

Re: Ways to compile C/C++ code for pi

Posted: Tue Aug 13, 2019 12:48 pm
by jahboater
The compiler installed by default is called GCC.
It is a very popular and capable compiler.
The letters GCC stand for Gnu Compiler Collection.
According to "gcc -v", it will compile:

C
Ada
C++
Go
Fortran
Objective C

and supports the latest standards, such as: C18, C++17, Fortran 2018

Re: Ways to compile C/C++ code for pi

Posted: Tue Aug 27, 2019 3:04 am
by moirainesedai
Also highly recommend clang/LLVM. In most cases they can be used as drop-in replacement for gcc.

Re: Ways to compile C/C++ code for pi

Posted: Tue Aug 27, 2019 3:24 am
by Gavinmc42
It seems like almost all languages can compile on Pi's.
I have used C, C++, D, Go, Rust, Free Pascal, Pony, Luajit.....
Then there are ones that are interpreted, Python, Lua, TCL, ....

I normally use Geany as my default editor/IDE, it know most languages.

Re: Ways to compile C/C++ code for pi

Posted: Wed Aug 28, 2019 4:34 pm
by cmrincon
Cross compilation is an option.

I use Visual Studio 2017, im sure that you can google how to set up your VS in case you decide to use it.

Re: Ways to compile C/C++ code for pi

Posted: Thu Aug 29, 2019 3:00 pm
by Snerler
cmrincon wrote:
Wed Aug 28, 2019 4:34 pm
Cross compilation is an option.

I use Visual Studio 2017, im sure that you can google how to set up your VS in case you decide to use it.
Do you have a good guide for this?

Re: Ways to compile C/C++ code for pi

Posted: Thu Aug 29, 2019 5:45 pm
by DougieLawson
You need to call the Emergency Services, your local Google is in need of medical attention.

https://docs.microsoft.com/en-us/cpp/li ... ew=vs-2019

Re: Ways to compile C/C++ code for pi

Posted: Thu Aug 29, 2019 5:54 pm
by cmrincon
Download Visual Studio Comunity 2019:
https://visualstudio.microsoft.com/es/downloads/

Instalation:
https://docs.microsoft.com/en-us/cpp/li ... ew=vs-2019

Create the project:
https://devblogs.microsoft.com/cppblog/ ... al-studio/

omit gdbserver instalation as in raspbian is installed by default.
The tutorial is targeted to linux machines but you can notice that in the create project window there is a "blink (raspberry)" option which is the one i recommend you as a hello world program.

blink (raspberry) option will configure VS to work with raspberry and you will only need to enter hostname, username and password of the raspberry account. Don't try to configure VS from scratch, it can be a headache for newbies because there are soo many options.

You can get the hostname of the raspberry by tiping in the console "hostname"
You can get the username of the raspberry by tiping "whoami"
Default port is 22.

Aditional resources:
https://docs.microsoft.com/en-us/visual ... ew=vs-2019