Skip to content

Instantly share code, notes, and snippets.

@AshyIsMe
Created April 30, 2021 02:34
Show Gist options
  • Save AshyIsMe/471f01920af2dc4349a7fb72ea3e8762 to your computer and use it in GitHub Desktop.
Save AshyIsMe/471f01920af2dc4349a7fb72ea3e8762 to your computer and use it in GitHub Desktop.
gcc9 in nix-shell
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = [
pkgs.gcc9
pkgs.gmp
pkgs.primesieve
];
}
# Usage:
# nix-shell gcc-env.nix
# gcc foo.c
#include <stdio.h>
#include <primesieve.h>
int main() {
printf("primesieve version %s\n", PRIMESIEVE_VERSION);
printf("compiler version %s\n", __VERSION__);
return 0;
}
# This seems a bit hacky but it gets around the `nix-shell -p gcc9 --run 'gcc --version' => 'gcc 10.x...'` problem
nix-shell gcc-env.nix
nix run nixpkgs.gcc9
gcc --version
# gcc (GCC) 9.3.0
# Copyright (C) 2019 Free Software Foundation, Inc.
# This is free software; see the source for copying conditions. There is NO
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
gcc primesieve.c
./a.out
# primesieve version 7.6
# compiler version 9.3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment