[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: setup c/c++ development environment

From: Fredrik Salomonsson
Subject: Re: setup c/c++ development environment
Date: Thu, 04 Mar 2021 11:02:43 -0800

Hi Roy,

Roy Lemmon <> writes:

> I would like to setup a c/c++ development environment on guix. At the moment, 
> I
> have used gcc-toolchain to bring in the compiler etc. Are other pieces
> necessary ?

That would be the bare minimum for c/c++. I would recommend using a
build system to build your stuff like GNU autotools[0], cmake[1] or


For the ease of use I would recommend meson.

A cool thing I learned from the Guix days last year was from the talk
"Just build it with Guix" by Efraim Flashner [3]. And that was using
guix to do the testing. It works really well.


Here is a simplified template of what I use for C++. It uses meson to
build and googletest[4] as the testing framework. But it should be
fairly simple to change to autotools or cmake or another testing
framework, e.g. catch2 [5].


  (guix build-system meson)
  (guix gexp)
  (guix git-download)
  (guix packages)
  (guix utils)
  ((guix licenses) #:prefix license:)
  (gnu packages pkg-config)
  (gnu packages check)
  (gnu packages build-tools)
  (gnu packages gcc)
  (ice-9 popen)
  (ice-9 rdelim)

;; From the talk "Just build it with Guix" by Efraim Flashner
;; presented on the Guix days 2020
(define %source-dir (dirname (current-filename)))

(define %git-commit
  (read-string (open-pipe "git show HEAD | head -1 | cut -d ' ' -f2" 

(define (skip-git-and-build-directory file stat)
  "Skip the `.git` and `build` directory when collecting the sources."
  (let ((name (basename file)))
    (not (or (string=? name ".git")
             (string=? name "build")))))

(define-public package-name-here
    (name "package-name-here")
    (version (git-version "0.1.0"  "HEAD" %git-commit))
    (source (local-file %source-dir
                        #:recursive? #t
                        #:select? skip-git-and-build-directory))
    (build-system meson-build-system)
     `(#:meson ,meson-0.55
       ;; Pass flags to meson
       ;; #:configure-flags '("-Dinstall=true")
    (native-inputs `(("pkg-config" ,pkg-config)
                     ("googletest" ,googletest)
                     ("gcc" ,gcc-9)))
    (synopsis "Template for building with meson.")
    (description "Simple template for building with meson-0.55 and gcc-9. Using
googletest as the testing framework.")
    ;; (home-page "https://...";)
    (license license:gpl3+)


To use it, simply copy the template above into a file called guix.scm,
update the package-name-here and version accordingly and place it at the
root of your project. Note the trailing `package-name-here` at end of
the template, which is there to return a package definition to guix.

Then you can run:

  guix build -f guix.scm

That build your project and run the tests.

If you want to place the guix.scm in a subdirectory, say build-aux.
  (define %source-dir (dirname (current-filename)))
  (define %source-dir (dirname (current-source-directory)))

In the template above.

After that you just run it with

  guix build -f build-aux/guix.scm

I hope that helps.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]