User:Sam/Musl porting notes
- Plenty of macros defined in glibc are actually there for compatibility reasons, but then are depended on by upstreams. Musl drops these, so we have to use the actual POSIX-provided versions instead.
MAXNAMLEN not defined here
MAXNAMLENdoesn't exist in musl. It's actually an alias in glibc.
NAME_MAXis defined, use that (ifdef). If not, fall back to
MSG_TRYHARDonly exists in glibc (
getopt was not declared in this scope
- In musl, a lot of headers are moved into separate files.
undefined reference to fts_read
- glibc provides extra functions which are not part of POSIX.
- Upstreams depend on these without doing so explicitly.
- Use one of the various standalone packages. Here, we need sys-libs/fts-standalone.
- Note that this is a common class of problems. See here for more information.
- This is a simple fix, add this to e.g. DEPEND:
elibc_musl? ( sys-libs/fts-standalone )
error: assignment of read-only variable '[stdout|stdin|stderr]'
- In musl stdout, stdin and stderr are read-only and cannot be set like in glibc 
Use freopen("standard-output-file", "w", stdout); instead of stdout = fopen ("standard-output-file", "w");
undefined reference to getpt
- Same as above.
posix_openpt()(with appropriate flags).
- "net-misc/vmnet-0.4: vmnet.c:(.text+<snip>): undefined reference to getpt" bug #712470
error.h: No such file or directory
- musl does not include the error.h header because "these functions and variables are GNU extensions, and should not be used in programs intended to be portable."
- Just remove the include for
error.h, usually, and relevant code if possible & harmless (often the case).
- "net-libs/iax-0.2.2-r3 : iax.c: fatal error: error.h: No such file or directory " bug #712510
glibc includes various extra functions which are not part of POSIX, so musl does not include them. User:blueness has ported and added the common ones to Gentoo:
- sys-libs/fts-standalone (adds fts - functions to traverse directories etc)
- sys-libs/obstack-standalone (obstack in glibc)
- sys-libs/queue-standalone (queue.h)
- sys-libs/rpmatch-standalone (used for 'yes/no' questions)
- sys-libs/argp-standalone (extends getopt)
If you discover a patch in another distro (or contribute one yourself!), please add PATCH to the keywords (if you have permissions) and comment with a link to the patch. File a new bug if one does not already exist.
Patches from other distros
If you're stuck, it may be worth seeing what other musl-using distros have done to fix the problem. Be aware that some distros, like Alpine, include compatibility packages by default (for now), so you may need to keep searching.
You can look at Alpine or Void Linux too, but they do not seem to have an easy listing of patches like the above.