Skip to content

Commit 64df1dd

Browse files
committed
Add more details on Native Image mostly static linking
(cherry picked from commit 2a54b94)
1 parent 5ab6f03 commit 64df1dd

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

docs/reference-manual/native-image/guides/build-static-and-mostly-static-executable.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ However, you can create a statically linked or mostly-static linked native execu
1515
A static native executable is easy to distribute and deploy on a slim or distroless container (a scratch container).
1616
You can create a static native executable by statically linking it against [musl-libc](https://musl.libc.org/), a lightweight, fast and simple `libc` implementation.
1717

18-
**A mostly-static native executable** is a binary that links everything except the standard C library, `glibc`. This is an alternative option to staticly linking everything.
18+
**A mostly-static native executable** is a binary that links everything (`zlib`, JDK shared libraries) except the standard C library, `libc`. This is an alternative option to staticly linking everything. Also, depending on the user's code, it may link `libstdc+` and `libgcc`.
1919
This approach is ideal for deployment on a distroless container image.
2020

21-
> Note: This currently only works when linked against `glibc`.
21+
> Note: This currently only works when linked against `libc`.
2222
2323
This guide shows how you can take advantage of Native Image linking options including fully dynamic, fully static, and mostly static (except `libc`) to generate an executable ideal for your deployment scenario.
2424

@@ -100,8 +100,7 @@ This application iterates over your environment variables and prints out the one
100100
101101
## Build a Mostly-Static Native Executable
102102
103-
With GraalVM Native Image you can build a mostly-static native executable that statically links everything except `libc`.
104-
Statically linking all your libraries except `glibc` ensures your application has all the libraries it needs to run on any Linux `glibc`-based distribution.
103+
With GraalVM Native Image you can build a mostly-static native executable that statically links everything except `libc`. Statically linking all your libraries except `libc` ensures your application has all the libraries it needs to run on any Linux `libc`-based distribution.
105104
106105
To build a mostly-static native executable, use this command:
107106
@@ -115,12 +114,15 @@ To build a a mostly-static native executable for the above `EnvMap` demo, run:
115114
native-image -H:+StaticExecutableWithDynamicLibC EnvMap
116115
```
117116
117+
This produces a native executable that statically links all involved libraries (including JDK shared libraries) except for `libc`. This includes `zlib`. Also, depending on the user's code, it may link `libstdc+` and `libgcc`.
118+
One way to check what dynamic libraries your application depends on is to run `ldd` with the native executable, for example, `ldd helloworld`.
119+
118120
### Frequently Asked Questions
119121
120122
#### What is the recommended base Docker image for deploying a static or mostly-static native executable?
121123
122124
A fully static native executable gives you the most flexibility to choose a base container image - it can run on anything including a `FROM scratch` image.
123-
A mostly-static native executable requires a container image that provides `glibc`, but has no additional requirements.
125+
A mostly-static native executable requires a container image that provides `libc`, but has no additional requirements.
124126
In both cases, choosing the base container image generally depends on your native executable's specific requirements.
125127
126128
### Related Documentation

0 commit comments

Comments
 (0)