SCons build with development gcc8

2

I'm attempting to build MongoDB v4.0 on CentOS7 (https://github.com/mongodb/mongo/wiki/Build-Mongodb-From-Source), and am unfamiliar with the python toolset included for building. The toolset requires gcc8.2 or newer, which I have installed with devtoolset-8-gcc and devtoolset-8-g++. I enable the toolset using scl enable devtoolset-8 bash And execute the scons build following the build guide, however scons appears to build its own environment which doesnt include the library at /opt/rh/devtoolset-8/.

[user@localhost mongo.git]$ sudo scl enable devtoolset-8 bash
[sudo] password for user:
[root@localhost mongo.git]# gcc --version
gcc (GCC) 8.2.1 20180905 (Red Hat 8.2.1-3)
Copyright (C) 2018 Free Software Foundation, Inc.
...
[root@localhost mongo.git]# ./buildscripts/scons.py
scons: Reading SConscript files ...
scons version: 2.5.0
python version: 2 7 5 'final' 0
...
Checking if C compiler is GCC 8.2 or newer...no
Checking if C++ compiler is GCC 8.2 or newer...no
ERROR: Refusing to build with compiler that does not meet requirements
See /opt/mongodb/mongo.git/build/scons/config.log for details

The log file contents are available at https://pastebin.com/jB2q4NxN.

My attempts to modify the python script to include the path per the scons manual have netted another error:

[root@localhost mongo.git]# buildscripts/scons.py all
Traceback (most recent call last):
  File "buildscripts/scons.py", line 7, in <module>
    env = Environment(ENV = {'PATH' : os.environ['PATH']})
NameError: name 'Environment' is not defined

After I added the lines

import os
env = Environment(ENV = {'PATH' : os.environ['PATH']})

To my buildscripts/scons.py file. Am I adding this in the wrong place perhaps? Why is the environment variable not available?

Thanks.

gangr33n

Posted 2019-04-05T11:01:36.587

Reputation: 23

You are already logged in as root, so sudo is unnecessary and will change to a new environment. You should be able to build fine as a normal (non-root) user or without sudo. There should be no need to modify the MongoDB build scripts; this is a hint that you're probably taking an incorrect approach. – Stennie – 2019-04-06T00:03:46.630

Hi Stennie. Good catch, thanks, but the same error remains.

[user@localhost mongo.git]$ sudo scl enable devtoolset-8 bash [sudo] password for user: [root@localhost mongo.git]# ./buildscripts/scons.py scons: Reading SConscript files ... scons version: 2.5.0 python version: 2 7 5 'final' 0 ... Checking if C compiler is GCC 5.3.0 or newer...no Checking if C++ compiler is GCC 5.3.0 or newer...no ERROR: Refusing to build with compiler that does not meet requirements See /opt/mongodb/mongo.git/build/scons/config.log for details – gangr33n – 2019-04-08T07:29:01.730

Can you edit your question to include the output of /opt/mongodb/mongo.git/build/scons/config.log (or a link to pastebin/gist if it's too large to include inline)? – Stennie – 2019-04-08T07:56:40.507

I have added a link. It appears to just reiterate the error. – gangr33n – 2019-04-08T09:27:51.603

Answers

0

Just name the path to the compiler with the CC and CXX Variables on the SCons command line:

scons CC=/path/to/toolset/gcc CXX=/path/to/toolset/g++

Please note however, that GCC 8 is not officially supported for building MongoDB 4.0. You may find that it doesn't build, or that it builds with warnings that are promoted to errors. You can work around some of them by adding the flag --disable-warnings-as-errors to your SCons invocation.

The reason you don't see the environment variables in your build is that SCons by default ignores the users environment in the interest of producing reproducible builds. If you really want to let SCons see the current shell environment, you can add --variables-files=etc/scons/propagate_shell_environment.vars to your SCons invocation.

acm

Posted 2019-04-05T11:01:36.587

Reputation: 168

1Thanks acm this seems to have gotten past the issue.

The git page wiki says that gcc8.2 is essential, as does the install from mongodb source, so it doesn't make sense to me that gcc8 would not be supported? I'm not using gcc8 by choice, it appears mandatory... – gangr33n – 2019-04-08T15:52:29.703

@gangr33n - Which git wiki page? – acm – 2019-04-08T17:09:13.123

The one I included at the start of my post. https://github.com/mongodb/mongo/wiki/Build-Mongodb-From-Source

– gangr33n – 2019-04-09T08:21:40.900

@gangr33n - Thanks for clarifying. Unfortunately, the github wiki doesn't track the versions of the server, so it can only ever reflect the build situation on the master branch. Older branches have different requirements. You may do better to review the BUILDING.md file for the branch of interest. For MongoDB 4.0, that is https://github.com/mongodb/mongo/blob/v4.0/docs/building.md

– acm – 2019-04-09T14:57:32.073

Excellent. Thanks acm. – gangr33n – 2019-04-10T10:43:06.790

@gangr33n - No problem. Would you mind clicking the 'accept' button for this answer since it solved your problem? That way the next person to encounter this issue will see that there is a known solution. – acm – 2019-04-10T11:57:32.363