Skip to content

Commit 2db8942

Browse files
authored
doc/stdenv/cross-compilation: Add 'Using -static outside a isStatic platform' (#344985)
2 parents 34b2da0 + 3f144b1 commit 2db8942

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

doc/stdenv/cross-compilation.chapter.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,31 @@ Example of an error which this fixes.
181181

182182
`[Errno 8] Exec format error: './gdk3-scan'`
183183

184+
#### Using `-static` outside a `isStatic` platform. {#cross-static-on-non-static-platform}
185+
186+
Add `stdenv.cc.libc.static` (static output of glibc) to `buildInputs` conditionally on if `hostPlatform` uses `glibc`.
187+
188+
189+
e.g.
190+
191+
```nix
192+
{
193+
buildInputs = lib.optionals (stdenv.hostPlatform.libc == "glibc") [ stdenv.cc.libc.static ];
194+
}
195+
```
196+
197+
Examples of errors which this fixes.
198+
199+
`cannot find -lm: No such file or directory`
200+
201+
`cannot find -lc: No such file or directory`
202+
203+
::: {.note}
204+
At the time of writing it is assumed the issue only happens on `glibc` because it splits the static libraries in to a different output.
205+
206+
::: {.note}
207+
You may want to look in to using `stdenvAdapters.makeStatic` or `pkgsStatic` or a `isStatic = true` platform.
208+
184209
## Cross-building packages {#sec-cross-usage}
185210

186211
Nixpkgs can be instantiated with `localSystem` alone, in which case there is no cross-compiling and everything is built by and for that system, or also with `crossSystem`, in which case packages run on the latter, but all building happens on the former. Both parameters take the same schema as the 3 (build, host, and target) platforms defined in the previous section. As mentioned above, `lib.systems.examples` has some platforms which are used as arguments for these parameters in practice. You can use them programmatically, or on the command line:

0 commit comments

Comments
 (0)