Skip to main content
This doc relates to the below revision of hardware
Mecha Logo

Comet (rev5)

For Pilot users

The all new Mecha Comet

Better in all ways, the next revision of Mecha Comet, coming soon.

C / C++

C and C++ are powerful programming languages commonly used for system-level programming, embedded systems, and performance-critical applications. Both languages can be compiled using GCC (GNU Compiler Collection) or Clang (LLVM-based compiler).

Using GCC

Launch terminal on your Comet or connect via SSH and run the below command.

$ sudo apt update
$ sudo apt install -y build-essential

This installs GCC along with common tools like make and libraries required for compilation. Run the below command to verify if gcc is installed and configured correctly.

$ gcc --version
$ g++ --version

Using Clang

Launch terminal on your Comet or connect via SSH and run the below command.

$ sudo apt update
$ sudo apt install -y clang

This installs Clang along with common tools like make and libraries required for compilation. Run the below command to verify if clang is installed and configured correctly.

$ clang --version
$ clang++ --version

Running an example

Let's create a simple "Hello, World!" program to test the installation for both compilers.

1

Create a new directory, and a new source file.

$ mkdir hello_world && cd hello_world
$ nano main.c
2

Paste the following program in the editor

#include <stdio.h>
int main() {
printf("Hello, C!\n");
return 0;
}
3

Now lets compile and run the program.

# Using gcc
$ gcc main.c -o hello_world
$ ./hello_world
Hello, C!

# Using clang
$ clang main.c -o hello_world
$ ./hello_world
Hello, C!

That's it now with gcc or clang installed, you are ready for compiling and running C programs!