且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

GCC在Alpine Linux中找不到stdio.h

更新时间:2023-11-22 16:34:58

除GCC之外,还安装 libc-dev ,或仅安装 build-base strong>( alpine-sdk 可能是一个过大的杀伤力)。要安装,请运行以下命令:

  apk add libc-dev 

您需要单独安装,因为在Alpine Linux中,GCC软件包不依赖 libc- dev 有充分的理由


您可以使用gcc编译没有libc的东西,例如管理程序固件等。


August Klein还指出,在Debian中,GCC仅出于相同的原因推荐 libc-dev (但大多数人不这样做-无安装建议)。


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

Install libc-dev in addition to GCC, or just install build-base for everything (alpine-sdk is probably an overkill). To install run the following command:

apk add libc-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).