Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC can't find stdio.h in Alpine Linux

Tags:

gcc

alpine

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 
like image 427
Franklin Yu Avatar asked Feb 21 '17 12:02

Franklin Yu


People also ask

Where is Stdio H located in Linux?

p.s. the standard location on *nix systems would be /usr/include/stdio. h, i.e., #include looks in /usr/include and other -I directories passed as arguments to the compiler. Show activity on this post. stdio.

Why is Stdio H not working?

Assuming C h> is one of the standard C headers. Your compiler complains that it can not find this header. This means that your standard library is broken. Consider reinstalling your compiler.


1 Answers

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

like image 75
Franklin Yu Avatar answered Sep 18 '22 04:09

Franklin Yu