Search code examples
mongodbgccbuildclangscons

clang error compiling mongodb from source


I took a git checkout of mongodb source files and am trying to compile it. I have gcc installed as part of xcode-7.3.1 command-line tools

Now when I am trying to build the mongodb binaries using:

scons all

I am getting the below error:

scons: Reading SConscript files ...
scons version: 2.5.0
python version: 2 7 10 'final' 0
Checking whether the C compiler works... yes
Checking whether the C++ compiler works... yes
Checking that the C++ compiler can link a C++ program... yes
Checking if C++ compiler "g++" is GCC... no
Checking if C++ compiler "g++" is clang... yes
Checking if C compiler "gcc" is clang... no
C compiler does not match identified C++ compiler
See /Users/debashish.g/mongo-code/mongo/build/scons/config.log for details

In the config log it shows:

scons: Configure: Checking if C compiler "gcc" is clang...
build/scons/sconf_temp/conftest_5.c <-
|
|#if defined(__clang__)
|/* we are using toolchain defined(__clang__) */
|#else
|#error
|#endif
|
gcc -o build/scons/sconf_temp/conftest_5.o -c     build/scons/sconf_temp/conftest_5.c
build/scons/sconf_temp/conftest_5.c:5:2: error: #error
#error
^~~~~
scons: Configure: no

My gcc --version shows :

Configured with: -- prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-   dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
InstalledDir:   /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Which is clang. Where am I doing wrong? Please help. I am stuck on this for a long time now.


Solution

  • What I missed was clang and llvm tools . I took a checkout of the source files and did a build of the clang tools according to the steps mentioned here.