Skip to content

Carbon Language

From Googles Carbon Github Repo ….

“Carbon is fundamentally¬†a successor language approach, rather than an attempt to evolve C++ incrementally. It is designed around interoperability with C++ as well as large-scale adoption and migration for existing C++ codebases and developers. A successor language for C++ requires:

  • Performance matching C++, is an essential property for our developers.
  • Seamless, bidirectional interoperability with C++, such that a library anywhere in an existing C++ stack can adopt Carbon without porting the rest.
  • A gentle learning curve with reasonable familiarity for C++ developers.
  • Comparable expressivity and support for existing software’s design and architecture.
  • Scalable migration, with some level of source-to-source translation for idiomatic C++ code.

With this approach, we can build on top of C++’s existing ecosystem, and bring along existing investments, codebases, and developer populations. 

Installation:

  • Install homebrew
    • /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
    • If you have already installed homebrew in the past, then worth updating it with
      • brew update — Checks if anything is out of date
      • brew upgrade.
  • Install Bazel
    • brew install bazelisk
  • Install llvm
    • brew install llvm
    • echo ‘export PATH=”/usr/local/opt/llvm/bin:$PATH”‘ >> ~/.bash_profile
    • export LDFLAGS=”-L/opt/homebrew/opt/llvm/lib”
    • export CPPFLAGS=”-I/opt/homebrew/opt/llvm/include”
    • export CC=$(which clang)
  • Install Carbon
    • mkdir ~/Carbon; cd ~/Carbon
    • git clone https://github.com/carbon-language/carbon-lang
    • cd carbon-lang
    • Run Hello, World to check its working
      • bazel run //explorer — ./explorer/testdata/print/format_only.carbon
        • NOTE: This command takes a long time the first time you run it, just keep an eye out for errors. Eventually, you will see ‘Hello world!’ printed on the terminal. Subsequent times it’s much quicker.
  • You now have a working version of Carbon and are ready to get started….

Getting Started:

Create a folder where you can start to write carbon projects. I choice ~/Carbon/projects

I then created a folder to start my first project in ~/Carbon/projects.test

In this folder, I create a file called “test.carbon” and added the hello world example

And to run it I used the following command

And you will see something like this

Langauge Basics:

  1. Resources for learning Carbon