GCC can't find stdio.h in Alpine Linux

GccAlpine

Gcc Problem Overview


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

Gcc Solutions


Solution 1 - Gcc

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).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFranklin YuView Question on Stackoverflow
Solution 1 - GccFranklin YuView Answer on Stackoverflow