How do you use GNOME Builder to code C++ in Silverblue?

I’m trying to write C++ (and maybe other) code in Fedora Silverblue.

I would like to use the Flatpak of GNOME Builder, but I can’t figure out how to set it up so Builder can access a compiler like g++.

How do you get Flatpak IDEs to work?

I haven’t used c++ or gnome builder specifically, but generally flatpak IDE’s can be a pain from my experience. For java, i know you can just install the jdk someone where, give the flatpak permissions to access all files (there might be a more restrictive setting that works, but this is what I do) and get the IDE to point to the jdk when compiling code.

But for c++, you can install gcc or some other compilers as a flatpak (some may not be available). I don’t think those show in the gui, so you may have to use the command line for that. You may have to change settings to ensure that builder is using your flatpak compiler if you go this route.

The best solution is figure out a way to get the IDE to bundle any necessary compilers on its own (if it can) and use those.

Hope this helps.

I use the IntelliJ Flatpak for Java, and IntelliJ is able to download its own JDK, so I’m covered there. But I can’t figure out what to do for C/C++. I don’t know if I can get access to the compiler via another Flatpak, or somehow tap into a Toolbox, or if I have to use rpm-ostree to add the compiler, which I’d rather not do.

I have Geany in a Toolbox with gcc/g++, so I’m covered to some extent, but I’d like to use a “bigger” IDE like GNOME Builder, Eclipse, Apache Netbeans, or even Intellij if that is possible.

I see how GNOME Builder can hook up to Flatpaks and Toolbox containers, but I can’t get any of the runtimes or containers to compile my C++ program.

What do I need in a Toolbox, or which Flatpak runtime do I need?

So I was messing around with a silverblue vm, and I think I discovered something that works for me at least using toolboxes.

  1. Enter a toolbox
  2. Install builder using dnf, and run it. The package name is gnome-builder as opposed to builder on flatpak
  3. Try and build the program, you don’t have to create a file yet
  4. It will tell you of any missing dependencies, install them using dnf. For me I had to install meson, gcc, and clang
  5. Try to build the program again, it worked for me this time.

Note that I only did simple scripts, something more complex may need more dependencies.

I’m trying to use the Flatpak of GNOME Builder. Somebody must have the “secret” of how to build C++ programs with Toolbox or Flatpak containers.

Maybe this is a clue as to why GNOME Builder isn’t working in Fedora Silverblue. Here’s the error message on why my program won’t build:

Error: crun: executable file `meson` not found in $PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found

That was it. My Toolbox needed Meson.

Once I installed it in the Toolbox:

$ sudo dnf install meson

… I was able to use that Toobox as my application runtime in GNOME Builder .

HOWEVER, I had previously added some other packages to my Toolbox, and adding meson was not enough. I need to figure out what else I added that made the Toolbox usable for C++.

So this isn’t a solution just yet.

Here is the solution:

To use the GNOME Builder Flatpak with a Toolbox runtime for C++:

  1. Create a Toolbox and add the following:

$ sudo dnf install g++ meson libtool

  1. In GNOME Builder:

Under the Builder menu in the taskbar:

Start New Project

Pick C++ as your language

In your project, use the “pencil” button at the upper left to “Switch Surface” from Editor to Build Preferences (or click alt+,)

Under Application Runtimes, select your Toolbox

Use the “Switch Surface” box at the upper left to switch back to the Editor (or click alt+1)

Then either build (the “Hammer” icon) or run (the “Play” icon) your project. You should see output in the terminal.

The key is having the right packages in your Toolbox. I tested which packages were needed for C++, which was one fewer than in this helpful post:

Then it’s all about configuring your GNOME Builder project to use the Toolbox for its runtime.

2 Likes

This solution should work for the GNOME Builder Flatpak as well as the DNF-installed RPM.

If you want a Flatpak of a more traditional IDE for C++ coding try Code::Blocks:

I installed Code::Blocks and was able to compile a C++ program in Fedora Silverblue out of the box. It just works.

Code::Blocks is not a cutting-edge IDE, but it works well for C++, and you can’t beat the no-configuration install from Flatpak.

Click “Summary” for the first_run.txt file you see when you run Code::Blocks for the first time:

Summary

Here is the “first run” file that comes up when you start Code::Blocks:


https://www.flathub.org

------------------------------------------------------------------------------------
| Warning: You are running an unofficial Flatpak version of Code::Blocks IDE !!! |
------------------------------------------------------------------------------------

Please open issues under: https://github.com/flathub/org.codeblocks.codeblocks/issues


This version is running inside a container and is therefore not able
to access SDKs on your host system!

This flatpak provides a standard development environment (gcc, python, etc).
To see what's available:

  $ flatpak run --command=sh org.codeblocks.codeblocks
  $ ls /usr/bin (shared runtime)
  $ ls /app/bin (bundled with this flatpak)

To get support for additional languages, you have to install SDK extensions, e.g.

  $ flatpak install flathub org.freedesktop.Sdk.Extension.dotnet
  $ flatpak install flathub org.freedesktop.Sdk.Extension.golang

To enable selected extensions, set FLATPAK_ENABLE_SDK_EXT environment variable
to a comma-separated list of extension names (name is ID portion after the last dot):

  $ FLATPAK_ENABLE_SDK_EXT=dotnet,golang flatpak run org.codeblocks.codeblocks

To make this persistent, set the variable via flatpak override:

  $ flatpak override --user org.codeblocks.codeblocks --env=FLATPAK_ENABLE_SDK_EXT="dotnet,golang"

You can use

  $ flatpak search <TEXT>

to find others.