Search code examples
buildscons

Controlling scons environment checking options


I'm trying to build mongodb (open source version 4.2) which uses python and scons for building. The problem relates to scons rather than mongodb.

My build fails very early with Couldn't find OpenSSL crypto.h header and library. Verbose details are:

file /.../SConstruct,line 3042:
        Configure(confdir = build/scons/opt/sconf_temp)
scons: Configure: Checking for SSLeay_version(0) in C library crypto... 
build/scons/opt/sconf_temp/conftest_d6743137aeb7fb2674cc9632f9989034_0.c <-
  |
  |
  |#include "openssl/crypto.h"
  |
  |int
  |main() {
  |  SSLeay_version(0);
  |return 0;
  |}
  |
gcc -o build/scons/opt/sconf_temp/conftest_d6743137aeb7fb2674cc9632f9989034_0.o -c -std=c11 -ffp-contract=off -fno-omit-frame-pointer -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -O2 -Wno-unused-local-typedefs -Wno-unused-function -Wno-deprecated-declarations -Wno-unused-const-variable -Wno-unused-but-set-variable -Wno-missing-braces -Wno-exceptions -fstack-protector-strong -fno-builtin-memcmp -fPIE -DNDEBUG -D_XOPEN_SOURCE=700 -D_GNU_SOURCE build/scons/opt/sconf_temp/conftest_d6743137aeb7fb2674cc9632f9989034_0.c
cc1: error: command-line option '-Wno-exceptions' is valid for C++/ObjC++ but not for C [-Werror]
cc1: all warnings being treated as errors
scons: Configure: no

I'm using Arch Linux which has multiple OpenSSL packages, and the default 3.0 is not compatible with mongodb source. I also have OpenSSL 1.1 and 1.0 installed, and can switch with e.g. gcc -I/usr/include/openssl-1.1.

Unfortunately I have not found a way to instruct SConstruct to use this flag in the command lines it generates to check the environment. I have tried CFLAGS, CCFLAGS, CPPPATH both as environment variables and scons command line parameters.

I also tried reverse enginering it, and tracked this to Conftest and TryBuild but it's not obvious how I can influance theses from the command line, so I'm trying my luck with you guys before going deeper in scons code.


Solution

  • If you look at the SConstruct and search for openssl, you'll find this blurb under the logic to detect on macOS

                NOTE: Recent versions of macOS no longer ship headers for the system OpenSSL libraries.
                NOTE: Either build without the --ssl flag, or describe how to find OpenSSL.
                NOTE: Set the include path for the OpenSSL headers with the CPPPATH SCons variable.
                NOTE: Set the library path for OpenSSL libraries with the LIBPATH SCons variable.
                NOTE: If you are using HomeBrew, and have installed OpenSSL, this might look like:
                \tscons CPPPATH=/usr/local/opt/openssl/include LIBPATH=/usr/local/opt/openssl/lib ...
                NOTE: Consult the output of 'brew info openssl' for details on the correct paths."""
    

    I'd bet if you did the same but pointed at the proper locations on your system for the openssl libs and header files, you'd be able to build.

    (see: https://github.com/mongodb/mongo/blob/r4.2.0/SConstruct#L3015 )