gcc 无法在Linux Mint 15上编译程序

6tdlim6h  于 2023-02-23  发布在  Linux
关注(0)|答案(5)|浏览(174)

我试图在Linux Mint 15中运行一个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-essential

但我得到了以下错误:

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
olqngx59

olqngx591#

我也遇到了同样的问题,只是简单地安装了g++包,就修复了丢失的包含文件。
sudo apt-get install g++

jm2pwxwz

jm2pwxwz2#

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

sudo apt-get install libc6-dev

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

4dbbbstv

4dbbbstv3#

我以前遇到过这种情况:

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

这修复了错误。

iaqfqrcu

iaqfqrcu4#

FWIW,Mint 17只需要编译C程序所必需的build:

# 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.
whlutmcx

whlutmcx5#

当您尝试从错误的目录时可能会出现此问题...
我建议你查一下电话簿。
通过以下方式更新操作系统:sudo apt-获取更新。
最后一个选择是删除现有的gcc编译器并安装新的。
你也可以试试这个:
g ++-o [文件名][可执行文件名]

相关问题