77

In a fresh Alpine Linux I installed GCC by

apk add --update-cache gcc

but still a simple program

#include <stdio.h>

int main(int argc, char *argv[]) {
    return 0;
}

compiled with message

fatal error: stdio.h: No such file or directory

1 Answer 1

147

Install musl-dev (in addition to the gcc compiler)

apk add musl-dev

You need to install it separately because in Alpine Linux, the package GCC doesn't depend on libc-dev for good reason:

You can use gcc to compile things without libc, for example hypervisors firmware etc.

And August Klein also noted that in Debian, GCC only recommends libc-dev for the same reason (but most people don't do --no-install-recommends anyway).

4
  • 10
    apk add libc-dev
    – Leonardo
    Apr 24, 2017 at 17:20
  • 11
    Or, apk add musl-dev: libc-dev is a meta package that will pull musl-dev, which contains the actual files (pkgs.alpinelinux.org/…)
    – valiano
    Feb 1, 2019 at 15:13
  • 3
    Similarly, for me stdlib.h was missing and this fixed it. Jun 19, 2019 at 7:37
  • 1
    Thanks. It also resolves issue with sys/socket.h.
    – PRIHLOP
    Nov 26, 2019 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.