INSTALL 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. ==== Installing musl ====
  2. musl may be installed either as an alternate C library alongside the
  3. existing libraries on a system, or as the primary C library for a new
  4. or existing musl-based system.
  5. First, some prerequisites:
  6. - A C99 compiler with gcc-style inline assembly support, support for
  7. weak aliases, and support for building stand-alone assembly files.
  8. gcc 3.x and 4.x are known to work. pcc and LLVM/clang may work but
  9. are untested, and pcc is known to have some bugs.
  10. - GNU make
  11. - Linux, preferably 2.6.22 or later. Older versions are known to have
  12. serious bugs that will make some interfaces non-conformant, but if
  13. you don't need threads or POSIX 2008 features, even 2.4 is probably
  14. okay.
  15. - A supported CPU architecture (currently i386, x86_64, or arm).
  16. - If you want to use dynamic linking, it's recommended that you have
  17. permissions to write to /lib and /etc. Otherwise your binaries will
  18. have to use a nonstandard dynamic linker path.
  19. == Option 1: Installing musl as an alternate C library ==
  20. In this setup, musl and any third-party libraries linked to musl will
  21. reside under an alternate prefix such as /usr/local/musl or /opt/musl.
  22. A wrapper script for gcc, called musl-gcc, can be used in place of gcc
  23. to compile and link programs and libraries against musl.
  24. To install musl as an alternate libc, follow these steps:
  25. 1. Edit config.mak to select your system's CPU architecture (i386,
  26. x86_64, or arm), installation prefix, location for the dynamic
  27. linker, and other build preferences.
  28. 2. Run "make". Parallel build is fully supported, so you can instead
  29. use "make -j3" or so on SMP systems if you like.
  30. 3. Run "make install" as a user sufficient privileges to write to the
  31. destination.
  32. 4. Ensure that /etc/ld-musl-$ARCH.path (where $ARCH is replaced by
  33. i386, x86_64, etc. as appropriate) contains the correct search path
  34. for where you intend to install musl-linked shared library files.
  35. This step can be skipped if you disabled dynamic linking.
  36. After installing, you can use musl via the musl-gcc wrapper. For
  37. example:
  38. cat > hello.c <<EOF
  39. #include <stdio.h>
  40. int main()
  41. {
  42. printf("hello, world!\n");
  43. return 0;
  44. }
  45. EOF
  46. musl-gcc hello.c
  47. ./a.out
  48. To configure autoconf-based program to compile and link against musl,
  49. you may wish to use:
  50. CC="musl-gcc -D_GNU_SOURCE" ./configure ...
  51. Correctly-written build systems should not need -D_GNU_SOURCE as part
  52. of $CC, but many programs do not use feature-test macros correctly and
  53. simply assume the compiler will automatically give them the kitchen
  54. sink, so the above command is an easy workaround.
  55. You will probably also want to use --prefix when building libraries to
  56. ensure that they are installed under the musl prefix and not in the
  57. main host system library directories.
  58. Finally, it's worth noting that musl's include and lib directories in
  59. the build tree are setup to be usable without installation, if
  60. necessary. Just modify the musl-gcc wrapper's libc_prefix variable to
  61. point to the source/build tree.
  62. == Option 2: Installing musl as the primary C library ==
  63. In this setup, you will need an existing compiler/toolchain. It
  64. shouldnt matter whether it was configured for glibc, uClibc, musl, or
  65. something else entirely, but sometimes gcc can be uncooperative,
  66. especially if the system distributor has built gcc with strange
  67. options. It probably makes the most sense to perform the following
  68. steps inside a chroot setup or on a virtualized machine with the
  69. filesystem containing just a minimal toolchain.
  70. WARNING: DO NOT DO THIS ON AN EXISTING SYSTEM UNLESS YOU REALLY WANT
  71. TO CONVERT IT TO BE A MUSL-BASED SYSTEM!!
  72. 1. If you are just upgrading an existing version of musl, you can skip
  73. step 1 entirely. Otherwise, move the existing include and lib
  74. directories on your system out of the way. Unless all the binaries
  75. you will need are static-linked, you should edit /etc/ld.so.conf
  76. (or equivalent) and put the new locations of your old libraries in
  77. the search path before you move them, or your system will break
  78. badly and you will not be able to continue.
  79. 2. Edit musl's config.mak and set the installation prefix to the
  80. prefix your compiler toolchain is configured to search, probably
  81. /usr. Set ARCH to match your CPU architecture, and change any other
  82. options as you see fit.
  83. 3. Run "make" to compile musl.
  84. 4. Run "make install" with appropriate privileges.
  85. 5. If you are using gcc and wish to use dynamic linking, find the gcc
  86. directory containing libgcc.a (it should be something like
  87. /usr/lib/gcc/i486-linux-gnu/4.3.5, with the arch and version
  88. possibly different) and look for a specs file there. If none
  89. exists, use "gcc -dumpspecs > specs" to generate a specs file. Find
  90. the dynamic linker (/lib/ld-linux.so.2 or similar) and change it to
  91. "/lib/ld-musl-$ARCH.so.1" (with $ARCH replaced by your CPU arch).
  92. At this point, musl should be the default libc. Compile a small test
  93. program with gcc and verify (using readelf -a or objdump -x) that the
  94. dynamic linker (program interpreter) is /lib/ld-musl-$ARCH.so.1. If
  95. you're using static linking only, you might instead check the symbols
  96. and look for anything suspicious that would indicate your old glibc or
  97. uClibc was used.
  98. When building programs against musl, you may still want to ensure the
  99. appropriate feature test macros get defined, as in:
  100. CC="gcc -D_GNU_SOURCE" ./configure ...