User:Sam/Musl porting notes
- 1 Background
- 2 Common problems
- 2.1 MAXNAMLEN not defined here
- 2.2 MSG_DONTROUTE undeclared
- 2.3 getopt was not declared in this scope
- 2.4 undefined reference to fts_read
- 2.5 undefined reference to getpt
- 2.6 error.h: No such file or directory
- 3 Resources
- 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
- MAXNAMLEN doesn't exist in musl. It's actually an alias in glibc.
- Include <limits.h>.
- If NAME_MAX is defined, use that (ifdef). If not, fall back to MAXNAMLEN.
- MSG_TRYHARD only exists in glibc (_GNU_SOURCE set).
- Use MSG_DONTROUTE instead.
getopt was not declared in this scope
- In musl, a lot of headers are moved into separate files.
- Include <getopt.h>.
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 )
- "app-crypt/bsign-0.4.5-r1 : filewalk.cc:(.text+<snip>): undefined reference to fts_read" bug #712638
undefined reference to getpt
- Same as above.
- Replace getpt() with 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.
- "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.