[SERVER-32425] How to build MongoDB as a static executable Created: 20/Dec/17 Updated: 27/Oct/23 Resolved: 12/Jan/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Build |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Question | Priority: | Major - P3 |
| Reporter: | Praveen Arkeri | Assignee: | Andrew Morrow (Inactive) |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
I wanted to know if its possible to build 'mongod' statically. I am using following command and I see that build is success full but binary is still dynamically linked.. scons --link-model=static -j 44 CCFLAGS=" -march=armv8-a+crc -static" --disable-warnings-as-errors Any inputs on what compile options I should use to get statically linked executable? |
| Comments |
| Comment by Andrew Morrow (Inactive) [ 12/Jan/18 ] | ||||||||
|
Hi - I'm closing out this ticket since I haven't heard back from you. Feel free to update this ticket if you have any further questions. | ||||||||
| Comment by Andrew Morrow (Inactive) [ 04/Jan/18 ] | ||||||||
|
No idea about the relocation problems in libresolve.a: that looks like a platform issue that we can't really control. The warning about dlopen is pointing out that, as I stated above, dlopen is going to be weird in a fully static build. Perhaps it is not a problem unless you actually call dlopen? If you want that warning to not break the build, you can build with --disable-warnings-as-errors. You will still need to figure out the libresolv problem though. In general, static linking is deprecated on linux, and we make no effort to test or support fully static builds, so you are fighting an uphill battle here. You may well need to prune parts of the codebase out (shared_library_posix.cpp, whatever depends on libresolv) to make it work, sort of. | ||||||||
| Comment by Praveen Arkeri [ 04/Jan/18 ] | ||||||||
|
@AndrewM I added dependency of library 'dl' in top level Sconstruct file which resolved previous errors but few new ones have popped up now:
Errors:
| ||||||||
| Comment by Andrew Morrow (Inactive) [ 21/Dec/17 ] | ||||||||
|
Well, I think you fixed the first one by saying -static-libgcc. However, the other issue looks more serious. Can you build with VERBOSE=1, and see if the dl library is on the link line for mongod? If not, you could try adding LIBS="dl" to the SCons invocation. However, I'm not entirely sure what it means to use the libdl libraries from what is supposed to be a fully static build. It may be that this just isn't a supported configuration. So, let me ask: why do you want to build a fully static version of mongod? If you build it on a given linux distro, the dynamic build you get by default only links to system C ABI libraries, so should be moveable to any other ABI compatible version of that distro. Why is a static build needed? | ||||||||
| Comment by Praveen Arkeri [ 21/Dec/17 ] | ||||||||
|
Hi Andrew, Thanks for your inputs, I removed -static flag from CCFLAGS and added it to LINKFLAGS but I see more errors. LINKFLAGS=" -Wl,-static"
LINKFLAGS=" -Wl,-static -static-libgcc"
LINKFLAGS="-Wl,-static -static-libgcc -static-libstdc++"
Am I missing any other flags? | ||||||||
| Comment by Andrew Morrow (Inactive) [ 20/Dec/17 ] | ||||||||
|
I'm assuming that you are finding that the executable is still linked to system dynamic libraries? Given the - Please be aware that fully statically linked executables aren't necessarily supported - things like nsswitch and pam may not be fully supported by a link to the static C runtime. |