solaris 11 stdio.h: No such file or directory

http://www.zendo.name/solaris-11-stdio-h%EF%BC%9A-no-such-file-or-directory/

在Solaris 11下使用gcc编译器,安装编译器

1
pkg install gcc-45 或者 pkg install gcc-3

数字是gcc版本号

但是在进行编译时,会出现头文件错误,最基本的stdio.h也找不到

1
root@solaris11:~ # cat hello.c
1
2
3
4
5
6
7
8
#include <stdio.h>
int main( int argc, char * argv[])
{
     while (1) {
         getchar ();
     }
     return 0;
}
1
root@solaris11:~$ gcc hello.c
1
hello.c:1:19 fatal error: stdio.h: No such file or directory
1
root@solaris11:~$ slocate stdio.h
1
2
3
4
5
6
7
8
/usr/include/glib-2.0/glib/gstdio.h
/usr/include/libgsf-1/gsf/gsf-output-stdio.h
/usr/include/libgsf-1/gsf/gsf-outfile-stdio.h
/usr/include/libgsf-1/gsf/gsf-input-stdio.h
/usr/include/libgsf-1/gsf/gsf-infile-stdio.h
/usr/include/ast/ast_stdio.h
/usr/include/ast/stdio.h
/usr/gcc/4.5/lib/gcc/i386-pc-solaris2.11/4.5.2/include/ssp/stdio.h

用slocate寻找,找到了很多头文件,可是没用,难道是链接库的位置错误?不是,默认的solaris 11并没有安装完整的头文件,只需要安装system/header即可

1
pkg install system /header

这样就可以正常编译了,而solocate的结果里也会多出一项 /usr/gcc/4.5/include/c++/4.5.2/tr1/stdio.h

### 解决方案 对于在 Windows 环境下遇到 `stdio.h: No such file or directory` 的错误,通常是在使用 WSL (Windows Subsystem for Linux) 或者 MinGW 编译 C/C++ 程序时发生的。以下是针对不同情况的具体解决方案。 #### 使用WSL的情况 当通过 Windows 应用商店安装 Ubuntu 后,在尝试编译简单的 Hello World 程序时报错: ```bash root@Mack:/home/mack/test# gcc test.c test.c:1:10: fatal error: stdio.h: No such file or directory #include <stdio.h> ^~~~~~~~~ compilation terminated. ``` 这表明当前环境中缺少必要的开发工具包。为了修复这个问题,可以执行以下命令来更新软件源并安装构建必需的组件[^2]: ```bash sudo apt update && sudo apt upgrade -y sudo apt install build-essential ``` 上述操作完成后再次尝试编译应该能够正常工作。 #### 使用MinGW的情况 如果是在纯 Windows 平台上利用 MinGW 进行编程,则需要确保已经正确设置了环境变量,并且确认已下载了完整的 GCC 工具链。可以通过访问 [MinGW官网](http://www.mingw.org/) 下载最新版本的 MinGW 安装器。安装过程中记得勾选 "mingw32-base" 和 "mingw32-gcc-g++" 组件以获得完整的支持[^4]。 另外一种方式是采用 MSYS2 项目提供的更现代化替代品——它不仅包含了最新的 GCC 版本还提供了 Pacman 包管理器用于轻松获取其他依赖项。MSYS2 可以为用户提供更加稳定可靠的跨平台开发体验。 #### 验证安装成功与否的方法 无论是选择了哪种途径解决问题,都可以编写一段简单测试代码验证是否真的解决了问题: ```c // hello_world.c 文件内容如下所示 #include <stdio.h> int main() { printf("Hello, world!\n"); return 0; } ``` 接着运行相应的编译指令(取决于所使用的环境),比如对于 WSL 中的 Ubuntu 是 `gcc hello_world.c -o hello_world`;而对于 MinGW 则可能是 `mingw32-make.exe` 或直接调用 `gcc.exe` 来完成编译过程。如果没有再出现类似的报错信息即表示配置无误。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值