Unable to compile simple c program in Linux Mint 15

白昼怎懂夜的黑 提交于 2019-11-27 01:19:56

问题


I am a Linux Mint 15 User.
i wanted to write simple program in C.
Below is my code.(hw.c)

#include<stdio.h>
#include<conio.h>
int main()
{
    printf("Hello World");
}

But, when i try to compile it with gcc

gcc -o hw hw.c

it gives me an error

hw.c:1:18: fatal error: stdio.h: No such file or directory
compilation terminated.

I googled and found some solutions which say to install build-essential
and tried to install it

sudo apt-get install build-essintial

but it gives an error again. The error is

    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.

So what is wrong? What is the problem?
How to solve it?

PS. The result of locate stdio.h is

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

回答1:


I was having the same problem, and simply installed the g++ package and that fixed the missing include file.

sudo apt-get install g++




回答2:


I had this situation before:

    rleclerc@fvrwbp01:~# gcc -o tokens tokens.c
    tokens.c:1:19: fatal error: stdio.h: No such file or directory
    compilation terminated.

You wrote:

    sudo apt-get install build-essintial

There's a typo. Try this instead (I guess you already did something similar):

    sudo apt-get install --no-install-recommends gcc

and:

    sudo apt-get install --no-install-recommends build-essential

Sometimes, proof-reading makes some difference:

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

This fixed the error.




回答3:


FWIW, Mint 17 just needs build-essential to compile C programs:

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



回答4:


The package name for the C standard library is libc6. Its header files are in the development package: libc6-dev. Some Linux distributions do not have the development package installed. You need to install it yourself:

sudo apt-get install libc6-dev

Why the installation of build-essentials does not resolve the dependencies I don't know. But I think the question wasn't about the installation of build-essentials and maybe it isn't needed at all.

References:

  • https://packages.debian.org/en/sid/libc6
  • https://www.debian.org/doc/debian-policy/ch-sharedlibs.html#s-sharedlibs-dev
  • https://en.wikipedia.org/wiki/GNU_C_Library#A_temporary_fork



回答5:


This problem may come when you are trying from wrong directory...

I suggest you to check for directory.
Update the OS by: sudo apt-get update.
The final option is to remove the exixting gcc compiler and install the new one.

You can also try this:

g++ -o [fileName] [executable name]



来源:https://stackoverflow.com/questions/19500018/unable-to-compile-simple-c-program-in-linux-mint-15

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!