23

我是 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
4

5 回答 5

41

我遇到了同样的问题,只是安装了 g++ 包并修复了丢失的包含文件。

sudo apt-get install g++

于 2013-11-12T12:39:25.757 回答
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
    (...)

这修复了错误。

于 2014-03-26T16:15:11.443 回答
7

C 标准库的包名称是libc6. 它的头文件在开发包中:libc6-dev. 一些 Linux 发行版没有安装开发包。您需要自己安装它:

sudo apt-get install libc6-dev

为什么安装build-essentials不能解决我不知道的依赖关系。但我认为问题不在于安装,build-essentials也许根本不需要。

参考:

于 2015-09-18T13:49:10.897 回答
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.
于 2014-07-17T23:21:55.483 回答
0

当您从错误的目录尝试时,可能会出现此问题...

我建议你检查目录。
通过以下方式更新操作系统:sudo apt-get update。
最后一个选项是删除现有的 gcc 编译器并安装新的。

你也可以试试这个:

g++ -o [文件名] [可执行文件名]

于 2015-09-18T16:30:11.310 回答