【问题标题】:Unable to compile simple c program in Linux Mint 15无法在 Linux Mint 15 中编译简单的 c 程序
【发布时间】:2013-10-30 06:28:20
【问题描述】:

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

那么有什么问题吗?有什么问题?
如何解决?

附言。 locate stdio.h 的结果是

/usr/lib/perl/5.14.2/CORE/nostdio.h
/usr/lib/syslinux/com32/include/stdio.h

【问题讨论】:

  • 尝试sudo aptitude update 然后sudo aptitude upgrade 然后sudo aptitude install libc-dev g++ build-essential。请注意,&lt;conio.h&gt; 是 Windows 特定的标头,它不会在 Linux 上退出。并编译为gcc -Wall -g hw.c -o hw
  • conio.h 不是标准库中的标准 .h 文件。 POSIX中没有定义
  • 好的。我试图做 sudo aptitude install libc-dev g++ build-essential。但它说:不会安装、升级或删除任何包。 0 个软件包已升级,0 个新安装,0 个要删除,0 个未升级。需要获取 0 B 的档案。解包后将使用 0 B。但是问题并没有解决......
  • 您的问题是系统管理员问题。你跑了aptitude updateupgrade。请先修复您的系统。
  • 是的,我当然做了 aptitude 更新和升级

标签: linux gcc compiler-errors linux-mint


【解决方案1】:

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

sudo apt-get install g++

【讨论】:

  • 赞成这个,但它可能是 libc6-dev 包做到了。
  • 我在使用 Ceedling (Unity) 构建时遇到了 Mint 18.1 的问题,找不到 setjmp.h。添加 G++ 修复了它,但我同意我需要的只是开发包。
【解决方案2】:

我以前也遇到过这种情况:

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

这修复了错误。

【讨论】:

  • 错字:build-essintial --> build-essential 但编辑必须超过 6 个字符
【解决方案3】:

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

sudo apt-get install libc6-dev

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

参考资料:

【讨论】:

    【解决方案4】:

    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.
    

    【讨论】:

      【解决方案5】:

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

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

      你也可以试试这个:

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

      【讨论】:

        猜你喜欢
        • 2019-07-31
        • 2013-05-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-28
        • 1970-01-01
        相关资源
        最近更新 更多