Skip to content

Instantly share code, notes, and snippets.

@sirkha
Last active April 28, 2024 02:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirkha/8c6b8f23008baa1ee83cae193e728c77 to your computer and use it in GitHub Desktop.
Save sirkha/8c6b8f23008baa1ee83cae193e728c77 to your computer and use it in GitHub Desktop.
gem5 shell env
with import <nixpkgs>{};
stdenv.mkDerivation rec {
name = "gem5-git";
env = buildEnv { name = name; paths = buildInputs; };
zlib-dev = lib.getDev zlib;
zlib-lib = lib.getLib zlib;
buildInputs = [
mercurial
git
gcc
scons
gnum4
swig
pythonFull
gperftools
pcre
zlib-dev
zlib-lib
];
}
@sirkha
Copy link
Author

sirkha commented Oct 12, 2017

scons --verbose build/X86/gem5.opt

scons: Reading SConscript files ...
Warning: Your compiler doesn't support incremental linking and lto at the same time, so lto is being disabled. To force lto on anyway, use 
the --force-lto option. That will disable partial linking.
Warning: Protocol buffer compiler (protoc) not found.
         Please install protobuf-compiler for tracing support.
Checking for C header file Python.h... yes
Checking for C library python2.7... no
Error: can't find library python2.7 required by python

@sirkha
Copy link
Author

sirkha commented Oct 12, 2017

file /home/jkha/Sandbox/gem5/gem5/SConstruct,line 970:
    Configure(confdir = build/.scons_config)
scons: Configure: Checking for C header file Python.h... 
build/.scons_config/conftest_0.c <-
  |
  |#include <Python.h>
  |
  |
gcc -o build/.scons_config/conftest_0.o -c -pipe -fno-strict-aliasing -Wall -Wundef -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-error=suggest-override -Iinclude -Iext -I/nix/store/7dxqxqc68xfhip2rzi6vqn552f0f7phk-python-2.7.13/include/python2.7 -I/nix/store/7dxqxqc68xfhip2rzi6vqn552f0f7phk-python-2.7.13/include/python2.7 build/.scons_config/conftest_0.c
scons: Configure: yes

scons: Configure: Checking for C library python2.7... 
build/.scons_config/conftest_1.c <-
  |
  |
  |
  |int
  |main() {
  |  
  |return 0;
  |}
  |
gcc -o build/.scons_config/conftest_1.o -c -pipe -fno-strict-aliasing -Wall -Wundef -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-error=suggest-override -Iinclude -Iext -I/nix/store/7dxqxqc68xfhip2rzi6vqn552f0f7phk-python-2.7.13/include/python2.7 -I/nix/store/7dxqxqc68xfhip2rzi6vqn552f0f7phk-python-2.7.13/include/python2.7 build/.scons_config/conftest_1.c
gcc -o build/.scons_config/conftest_1 -Xlinker -export-dynamic build/.scons_config/conftest_1.o -lpython2.7
/nix/store/3iggy4d1wdwivs4kx9ic90npiwxvnrr8-binutils-2.27/bin/ld: cannot find -lpython2.7
collect2: error: ld returned 1 exit status
scons: Configure: no

@KoviRobi
Copy link

KoviRobi commented Apr 24, 2019

I find the following does the trick

index 5209aa6d4..c290aef4b 100755
--- a/SConstruct
+++ b/SConstruct
@@ -175,7 +175,8 @@ if GetOption('no_lto') and GetOption('force_lto'):
 #
 ########################################################################
 
-main = Environment()
+# For NixOS, based on https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/python-modules/cgkit/scons-env.patch
+main = Environment(ENV = os.environ)
 
 from gem5_scons import Transform
 from gem5_scons.util import get_termcap

Took me quite a while to figure it out, but turns out the SConstruct file was ignoring all the Nix environment variables that Nix shell sets up; this fixes that. Even if it's not useful to you, it might be useful to someone :)

@hakan-demirli
Copy link

hakan-demirli commented Sep 26, 2023

it might be useful to someone :)

Thank you.

I have been struggling with static glibc while compiling m5:

/nix/store/rhhll3vwpj38ri72ahrrrvcbkhz4fhh6-binutils-2.40/bin/ld: cannot find -lm: No such file or directory
/nix/store/rhhll3vwpj38ri72ahrrrvcbkhz4fhh6-binutils-2.40/bin/ld: cannot find -lc: No such file or directory

Changing the SConstruct file of m5 did it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment