我是Linux Mint 15用户。
我想在C中写简单的程序
下面是我的代码。(hw.c)
#include<stdio.h>
#include<conio.h>
int main()
{
printf("Hello World");
}
但是,当我尝试用gcc编译它时
gcc -o hw hw.c
它给了我一个错误
hw.c:1:18: fatal error: stdio.h: No such file or directory
compilation terminated.
我用谷歌搜索并找到一些解决方案,说安装build-essential
并试图安装它
sudo apt-get install build-essintial
但它再次出错。 错误是
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
build-essential : Depends: libc6-dev but it is not going to be installed or
libc-dev
Depends: g++ (>= 4:4.4.3) but it is not going to be installed
Depends: dpkg-dev (>= 1.13.5) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
那有什么不对?有什么问题?
怎么解决?
PS。
locate stdio.h
的结果是
/usr/lib/perl/5.14.2/CORE/nostdio.h
/usr/lib/syslinux/com32/include/stdio.h
答案 0 :(得分:35)
我遇到了同样的问题,只是安装了g ++软件包并修复了丢失的包含文件。
sudo apt-get install g++
答案 1 :(得分:8)
之前我遇到过这种情况:
rleclerc@fvrwbp01:~# gcc -o tokens tokens.c
tokens.c:1:19: fatal error: stdio.h: No such file or directory
compilation terminated.
您写道:
sudo apt-get install build-essintial
有一个错字。试试这个(我猜你已经做了类似的事情):
sudo apt-get install --no-install-recommends gcc
和
sudo apt-get install --no-install-recommends build-essential
有时候,校对会有所不同:
The following NEW packages will be installed:
build-essential dpkg-dev g++ g++-4.7 libc-dev-bin libc6-dev libdpkg-perl libstdc++6-4.7-dev libtimedate-perl linux-libc-dev make
(...)
这解决了错误。
答案 2 :(得分:6)
FWIW,Mint 17只需要build-essential来编译C程序:
# apt-get install build-essential
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
dpkg-dev g++ g++-4.8 libc-dev-bin libc6-dev libstdc++-4.8-dev
Suggested packages:
debian-keyring g++-multilib g++-4.8-multilib gcc-4.8-doc libstdc++6-4.8-dbg
glibc-doc libstdc++-4.8-doc
Recommended packages:
libalgorithm-merge-perl
The following NEW packages will be installed:
build-essential dpkg-dev g++ g++-4.8 libc-dev-bin libc6-dev
libstdc++-4.8-dev
0 upgraded, 7 newly installed, 0 to remove and 1 not upgraded.
答案 3 :(得分:6)
C标准库的包名称为libc6
。它的头文件位于开发包中:libc6-dev
。某些Linux发行版没有安装开发包。您需要自己安装:
sudo apt-get install libc6-dev
为什么build-essentials
的安装无法解决我不知道的依赖关系。但我认为问题不在于build-essentials
的安装,也许根本不需要。
参考文献:
答案 4 :(得分:0)
当您从错误的目录中尝试时,可能会出现此问题...
我建议你查一下目录 通过以下方式更新操作系统:sudo apt-get update 最后一个选项是删除exixting gcc编译器并安装新的编译器。
你也可以试试这个:
g ++ -o [fileName] [可执行文件名]