The odyssey of building MongoDB

63 views
Skip to first unread message

cb...@exa-online.de

unread,
Sep 20, 2017, 8:02:35 AM9/20/17
to mongodb-dev
Hi.

I am having a hard time trying to build MongoDB from it's sources:

I checked out the git repository and switched to the r3.4.9 tag.

1. using Arch Linux, the build failed because warnings were treated as errors and GCC is version 7.2.0... (compiler too new)

2. after having disabled `-Werror` (fair enough), the build failed because of a linking error. (I don't have the message anymore)

3. I switched to Debian Jessie (because that's the base image of the mongo Docker image), but the build failed (compiler too old)

Despite `docs/building.md` stating that "GCC 4.8.2 or newer" is required and Debian Jessie's GCC is version 4.9.x, it bails out saying that version 5.3.0 or newer is required.

4. I switched to Debian Stretch (in a Docker container) and the build failed

```
$ scons --disable-warnings-as-errors=true
...
Checking for C header file x86intrin.h... yes
IndexError: list index out of range:
  File "/develop/SConstruct", line 3063:
    env.SConscript('src/SConscript', variant_dir='$BUILD_DIR', duplicate=False)
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 541:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 250:
    exec _file_ in call_stack[-1].globals
  File "/develop/src/SConscript", line 14:
    ] + module_sconscripts
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 541:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 250:
    exec _file_ in call_stack[-1].globals
  File "/develop/src/mongo/SConscript", line 45:
    'util',
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 541:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 250:
    exec _file_ in call_stack[-1].globals
  File "/develop/src/mongo/installer/SConscript", line 7:
    'msi',
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 541:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/scons/SCons/Script/SConscript.py", line 250:
    exec _file_ in call_stack[-1].globals
  File "/develop/src/mongo/installer/msi/SConscript", line 89:
    major_version = "%s.%s" % (mv[0], mv[1])
```

Apparently, `git` is required during the build, since `git describe` is being called.

5. after `apt-get install git`, the build succeeded (yay!)

6. trying to build the unitttests fails

```
$ scons --disable-warnings-as-errors=true unittests
...
Compiling build/opt/mongo/base/parse_number_test.o
In file included from src/mongo/base/parse_number_test.cpp:37:0:
src/mongo/base/parse_number_test.cpp:295:49: error: exponent has no digits
     ASSERT_PARSES(double, "0xabcab.defdefP-10", 0xabcab.defdefP-10);
                                                 ^
src/mongo/unittest/unittest.h:106:93: note: in definition of macro '_ASSERT_COMPARISON'
             ::mongo::unittest::ComparisonAssertion_##COMPARISON(__FILE__, __LINE__, #a, #b, a, b)) \
                                                                                             ^
src/mongo/unittest/unittest.h:85:29: note: in expansion of macro 'ASSERT_EQ'
 #define ASSERT_EQUALS(a, b) ASSERT_EQ(a, b)
                             ^~~~~~~~~
src/mongo/base/parse_number_test.cpp:44:9: note: in expansion of macro 'ASSERT_EQUALS'
         ASSERT_EQUALS(static_cast<TYPE>(EXPECTED_VALUE), v); \
         ^~~~~~~~~~~~~
src/mongo/base/parse_number_test.cpp:295:5: note: in expansion of macro 'ASSERT_PARSES'
     ASSERT_PARSES(double, "0xabcab.defdefP-10", 0xabcab.defdefP-10);
     ^~~~~~~~~~~~~
scons: *** [build/opt/mongo/base/parse_number_test.o] Error 1
```

How can I build mongodb from sources (I want to make changes)?

What is the build environment that I should use to not run into troubles constantly? I already lost 2 days trying in vain to at least build the server, let alone the unit tests.

Thanks,
Claudio

Andrew Morrow

unread,
Sep 20, 2017, 8:25:25 AM9/20/17
to mongodb-dev
On Wed, Sep 20, 2017 at 7:58 AM, <cb...@exa-online.de> wrote:
Hi.

I am having a hard time trying to build MongoDB from it's sources:

I checked out the git repository and switched to the r3.4.9 tag.

1. using Arch Linux, the build failed because warnings were treated as errors and GCC is version 7.2.0... (compiler too new) 

2. after having disabled `-Werror` (fair enough), the build failed because of a linking error. (I don't have the message anymore)

As you found, --disable-warnings-as-errors is the correct approach. We require warning free builds for our developers when using our official toolchains, so it is important that the default be that warnings as errors. This flag is the escape hatch for when new compilers issue new diagnostics.

 

3. I switched to Debian Jessie (because that's the base image of the mongo Docker image), but the build failed (compiler too old) 

Despite `docs/building.md` stating that "GCC 4.8.2 or newer" is required and Debian Jessie's GCC is version 4.9.x, it bails out saying that version 5.3.0 or newer is required.

Yes, this looks like a bug.

The building.md file is correct on master but appears to not accurately reflect that GCC 5.4 is required on the 3.4 branch. However, for the 3.4 branch, only clang 3.4 is required.

Would you please file an issue here: https://jira.mongodb.org/projects/SERVER and we will get this corrected.

Note that it looks like Jesse does have a new enough clang, so you might just be able to use that.
Correct - we automatically derive our version information from git tags and the output of git describe. You can override this need by setting the SCons variables MONGO_VERSION and MONGO_GIT_HASH on the command line, if installing git is a difficulty. But it seems you worked around this.

 

5. after `apt-get install git`, the build succeeded (yay!) 

Happy to hear you got it working.

 

6. trying to build the unitttests fails

```
$ scons --disable-warnings-as-errors=true unittests
...
Compiling build/opt/mongo/base/parse_number_test.o
In file included from src/mongo/base/parse_number_test.cpp:37:0:
src/mongo/base/parse_number_test.cpp:295:49: error: exponent has no digits
     ASSERT_PARSES(double, "0xabcab.defdefP-10", 0xabcab.defdefP-10);
                                                 ^
src/mongo/unittest/unittest.h:106:93: note: in definition of macro '_ASSERT_COMPARISON'
             ::mongo::unittest::ComparisonAssertion_##COMPARISON(__FILE__, __LINE__, #a, #b, a, b)) \
                                                                                             ^
src/mongo/unittest/unittest.h:85:29: note: in expansion of macro 'ASSERT_EQ'
 #define ASSERT_EQUALS(a, b) ASSERT_EQ(a, b)
                             ^~~~~~~~~
src/mongo/base/parse_number_test.cpp:44:9: note: in expansion of macro 'ASSERT_EQUALS'
         ASSERT_EQUALS(static_cast<TYPE>(EXPECTED_VALUE), v); \
         ^~~~~~~~~~~~~
src/mongo/base/parse_number_test.cpp:295:5: note: in expansion of macro 'ASSERT_PARSES'
     ASSERT_PARSES(double, "0xabcab.defdefP-10", 0xabcab.defdefP-10);
     ^~~~~~~~~~~~~
scons: *** [build/opt/mongo/base/parse_number_test.o] Error 1
```


This has been fixed on master as part of https://jira.mongodb.org/browse/SERVER-23420, I've gone ahead and requested backport to 3.4.


 
How can I build mongodb from sources (I want to make changes)?

What is the build environment that I should use to not run into troubles constantly? I already lost 2 days trying in vain to at least build the server, let alone the unit tests.

If you are hoping to make changes to mongodb, I recommend actually working against the master branch, not a stable branch. Our workflow is that we make fixes on master and backport them to the older branches. Feature development only happens on master and is never backported. Note that if you do upgrade to the master branch you will find that you need at least GCC 5.4 or clang 3.8, which will make your system requirements that much stricter.

Personally, I develop on Ubuntu 16.04 which has both GCC 5.4 and clang 3.{8,9} and it works well for me.

Happy to answer any other questions.

Thanks,
Andrew

cb...@exa-online.de

unread,
Sep 21, 2017, 4:01:12 AM9/21/17
to mongodb-dev
Hi Andrew,

thanks for your reply, I appreciate it!


Am Mittwoch, 20. September 2017 14:25:25 UTC+2 schrieb acm:


On Wed, Sep 20, 2017 at 7:58 AM, <cb...@exa-online.de> wrote:

1. using Arch Linux, the build failed because warnings were treated as errors and GCC is version 7.2.0... (compiler too new) 

2. after having disabled `-Werror` (fair enough), the build failed because of a linking error. (I don't have the message anymore)

As you found, --disable-warnings-as-errors is the correct approach. We require warning free builds for our developers when using our official toolchains, so it is important that the default be that warnings as errors.

It would be good if the "official toolchain" was documented, e.g. like "we recommend GCC 5.3.x - if you use anything else you're on your own". I'll see whether I can reproduce the linking error, when I have the time. Or, is anybody else using GC 7.2 and ran into a linking error already?
 
3. I switched to Debian Jessie (because that's the base image of the mongo Docker image), but the build failed (compiler too old) 

Despite `docs/building.md` stating that "GCC 4.8.2 or newer" is required and Debian Jessie's GCC is version 4.9.x, it bails out saying that version 5.3.0 or newer is required.

Yes, this looks like a bug.

The building.md file is correct on master but appears to not accurately reflect that GCC 5.4 is required on the 3.4 branch. However, for the 3.4 branch, only clang 3.4 is required.

Would you please file an issue here: https://jira.mongodb.org/projects/SERVER and we will get this corrected.
 
Done: SERVER-31197
Yes, I figured it out reasonably quickly, but an error like "calling `git` failed, you have to set the MONGO_VERSION and MONGO_GIT_HASH variables instead" would have been better... :-)

6. trying to build the unitttests fails

```
$ scons --disable-warnings-as-errors=true unittests
...
Compiling build/opt/mongo/base/parse_number_test.o
In file included from src/mongo/base/parse_number_test.cpp:37:0:
src/mongo/base/parse_number_test.cpp:295:49: error: exponent has no digits
     ASSERT_PARSES(double, "0xabcab.defdefP-10", 0xabcab.defdefP-10);
                                                 ^
src/mongo/unittest/unittest.h:106:93: note: in definition of macro '_ASSERT_COMPARISON'
             ::mongo::unittest::ComparisonAssertion_##COMPARISON(__FILE__, __LINE__, #a, #b, a, b)) \
                                                                                             ^
src/mongo/unittest/unittest.h:85:29: note: in expansion of macro 'ASSERT_EQ'
 #define ASSERT_EQUALS(a, b) ASSERT_EQ(a, b)
                             ^~~~~~~~~
src/mongo/base/parse_number_test.cpp:44:9: note: in expansion of macro 'ASSERT_EQUALS'
         ASSERT_EQUALS(static_cast<TYPE>(EXPECTED_VALUE), v); \
         ^~~~~~~~~~~~~
src/mongo/base/parse_number_test.cpp:295:5: note: in expansion of macro 'ASSERT_PARSES'
     ASSERT_PARSES(double, "0xabcab.defdefP-10", 0xabcab.defdefP-10);
     ^~~~~~~~~~~~~
scons: *** [build/opt/mongo/base/parse_number_test.o] Error 1
```


This has been fixed on master as part of https://jira.mongodb.org/browse/SERVER-23420, I've gone ahead and requested backport to 3.4.

Thanks!
  
How can I build mongodb from sources (I want to make changes)?

What is the build environment that I should use to not run into troubles constantly? I already lost 2 days trying in vain to at least build the server, let alone the unit tests.

If you are hoping to make changes to mongodb, I recommend actually working against the master branch, not a stable branch. Our workflow is that we make fixes on master and backport them to the older branches. Feature development only happens on master and is never backported.

Yes, understood. I want to work on SERVER-17853 ($ne, $or, $not for partial filter expressions) but we need this sooner than later. So I want to get familiar with the code base for the current stable release first, and then submit my changes to the master branch later.
 
Note that if you do upgrade to the master branch you will find that you need at least GCC 5.4 or clang 3.8, which will make your system requirements that much stricter.
 
Personally, I develop on Ubuntu 16.04 which has both GCC 5.4 and clang 3.{8,9} and it works well for me.
 
Thanks!
Claudio

Andrew Morrow

unread,
Sep 21, 2017, 7:41:23 AM9/21/17
to mongodb-dev
On Thu, Sep 21, 2017 at 4:01 AM, <cb...@exa-online.de> wrote:
Hi Andrew,

thanks for your reply, I appreciate it!

Am Mittwoch, 20. September 2017 14:25:25 UTC+2 schrieb acm:


On Wed, Sep 20, 2017 at 7:58 AM, <cb...@exa-online.de> wrote:

1. using Arch Linux, the build failed because warnings were treated as errors and GCC is version 7.2.0... (compiler too new) 

2. after having disabled `-Werror` (fair enough), the build failed because of a linking error. (I don't have the message anymore)

As you found, --disable-warnings-as-errors is the correct approach. We require warning free builds for our developers when using our official toolchains, so it is important that the default be that warnings as errors.

It would be good if the "official toolchain" was documented, e.g. like "we recommend GCC 5.3.x - if you use anything else you're on your own".

You can basically read the minimum as recommended. Whatever versions of GCC, MSVC, XCode, and clang we have in place for a given release cycle is what we set as the minimum.

 

I'll see whether I can reproduce the linking error, when I have the time. Or, is anybody else using GC 7.2 and ran into a linking error already?

We have some developers who run arch and they tend to be the first to find these issues, and I don't recall seeing anything recently. If you repro it, please follow up. More than likely the fix will only be applied on master. We don't often backport fixes for newer compilers to older branches.


 
 
3. I switched to Debian Jessie (because that's the base image of the mongo Docker image), but the build failed (compiler too old) 

Despite `docs/building.md` stating that "GCC 4.8.2 or newer" is required and Debian Jessie's GCC is version 4.9.x, it bails out saying that version 5.3.0 or newer is required.

Yes, this looks like a bug.

The building.md file is correct on master but appears to not accurately reflect that GCC 5.4 is required on the 3.4 branch. However, for the 3.4 branch, only clang 3.4 is required.

Would you please file an issue here: https://jira.mongodb.org/projects/SERVER and we will get this corrected.
 
Done: SERVER-31197

Thanks. We will get that taken care of, or, feel free to send a pull request if you are interested.
You actually have to work a little hard to get into this situation:
- If you cloned the repo, then you have git, so everything works
- If you obtained our source tarballs from the downloads page, we interpolate in a version.json file which has the right contents, so git is not invoked?

How did you obtain the sources you are working with? In any event your point is good. Would you mind filing a ticket?
OK. Now that you are up and building, I recommend starting a new mongodb-dev thread explaining that you are interested in working on the ticket, providing some motivation, and outlining your approach. It is a not uncommon occurrence that work done by external developers ends up being impossible for us to merge because it either only partially solves the issue (i.e. ignores sharding, etc.) or because the approach is in conflict with other long term development plans. Reaching out now and giving an overview of what you intend to do will help ensure that the work you do is positioned for success.

cb...@exa-online.de

unread,
Oct 4, 2017, 5:30:58 AM10/4/17
to mongodb-dev
Hi.

Am Donnerstag, 21. September 2017 13:41:23 UTC+2 schrieb acm:
On Thu, Sep 21, 2017 at 4:01 AM, <cb...@exa-online.de> wrote:

Am Mittwoch, 20. September 2017 14:25:25 UTC+2 schrieb acm:

The building.md file is correct on master but appears to not accurately reflect that GCC 5.4 is required on the 3.4 branch. However, for the 3.4 branch, only clang 3.4 is required.

Would you please file an issue here: https://jira.mongodb.org/projects/SERVER and we will get this corrected.
 
Note that it looks like Jesse does have a new enough clang, so you might just be able to use that.

FTR, building with clang on Debian Jessie did not work out, as the libstdc++ files from GCC 5.3.0 are required here too and these are not available...

I want to build executables targeting Debian Jessie. Building on Debian stable does not work, because the libc6 is too new:

```
mongod: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.23' not found (required by mongod)
```

Do you know how the official deb packages are build? On which platform and how?

Thanks,
Claudio

Andrew Morrow

unread,
Oct 4, 2017, 7:22:40 AM10/4/17
to mongodb-dev
On Wed, Oct 4, 2017 at 5:30 AM, <cb...@exa-online.de> wrote:
Hi.

Am Donnerstag, 21. September 2017 13:41:23 UTC+2 schrieb acm:

On Thu, Sep 21, 2017 at 4:01 AM, <cb...@exa-online.de> wrote:

Am Mittwoch, 20. September 2017 14:25:25 UTC+2 schrieb acm:

The building.md file is correct on master but appears to not accurately reflect that GCC 5.4 is required on the 3.4 branch. However, for the 3.4 branch, only clang 3.4 is required.

Would you please file an issue here: https://jira.mongodb.org/projects/SERVER and we will get this corrected.
 
Note that it looks like Jesse does have a new enough clang, so you might just be able to use that.

FTR, building with clang on Debian Jessie did not work out, as the libstdc++ files from GCC 5.3.0 are required here too and these are not available...

You should be able to select a libc++ build by adding --libc++ to your SCons invocation. Assuming that Jesse has a working libc++ that may work fine.

 

I want to build executables targeting Debian Jessie. Building on Debian stable does not work, because the libc6 is too new:

```
mongod: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.23' not found (required by mongod)
```

Did you try to compile on debian stable and then run the binaries on Jesse? That definitely isn't expected to work because you will pick up dependencies on newer library versions during your build on stable which will not be provided by the versions on Jesse, as you have found here.

 

Do you know how the official deb packages are build? On which platform and how?

What do you mean by "official"? Do you mean the ones that we, MongoDB provide, or the ones built-in to debian? I don't know the answer to the latter, but for the former, the answer is that we build our own versions of GCC and clang for every linux distro that we plan to target.

Thanks,
Andrew

cb...@exa-online.de

unread,
Oct 4, 2017, 9:22:14 AM10/4/17
to mongodb-dev

Am Mittwoch, 4. Oktober 2017 13:22:40 UTC+2 schrieb acm:


On Wed, Oct 4, 2017 at 5:30 AM, <cb...@exa-online.de> wrote:
Hi.

Am Donnerstag, 21. September 2017 13:41:23 UTC+2 schrieb acm:

On Thu, Sep 21, 2017 at 4:01 AM, <cb...@exa-online.de> wrote:

Am Mittwoch, 20. September 2017 14:25:25 UTC+2 schrieb acm:

The building.md file is correct on master but appears to not accurately reflect that GCC 5.4 is required on the 3.4 branch. However, for the 3.4 branch, only clang 3.4 is required.

Would you please file an issue here: https://jira.mongodb.org/projects/SERVER and we will get this corrected.
 
Note that it looks like Jesse does have a new enough clang, so you might just be able to use that.

FTR, building with clang on Debian Jessie did not work out, as the libstdc++ files from GCC 5.3.0 are required here too and these are not available...

You should be able to select a libc++ build by adding --libc++ to your SCons invocation. Assuming that Jesse has a working libc++ that may work fine.
 
Thanks, that helped. :-)

Do you know how the official deb packages are build? On which platform and how?

What do you mean by "official"? Do you mean the ones that we, MongoDB provide, or the ones built-in to debian?

Yes, I meant the "official" debs at http://repo.mongodb.org which are used in the debian:jessie-slim based Docker image.


 > I don't know the answer to the latter, but for the former, the answer is that we build our own versions of GCC and clang for every linux distro that we plan to target.

Ha, I almost went down the same road, my GCC compilation already running for an hour until I saw your answer... ;-)

Thanks!
Claudio

Andrew Morrow

unread,
Oct 4, 2017, 12:32:32 PM10/4/17
to mongodb-dev

Happy to hear you are making progress without needing to roll your own toolchain.

--
You received this message because you are subscribed to the Google Groups "mongodb-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-dev+unsubscribe@googlegroups.com.
To post to this group, send email to mongo...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-dev/44a3d95a-44a1-4a1c-895d-95b1071f2892%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages