23

I'm trying to run a C program in Linux Mint 15, but without success.

Here is my code:

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

I compile with gcc:

gcc -o hw hw.c

But, I get the following error:

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

I researched the problem and found some solutions that say to install build-essential, so I did:

sudo apt-get install build-essential

But I get the following error:

    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.

How do I resolve this and make my program run correctly?

EDIT: The result of locate stdio.h is:

/usr/lib/perl/5.14.2/CORE/nostdio.h
/usr/lib/syslinux/com32/include/stdio.h
namco
  • 6,208
  • 20
  • 59
  • 83
  • 4
    Try `sudo aptitude update` then `sudo aptitude upgrade` then `sudo aptitude install libc-dev g++ build-essential`. Notice that `` is a Windows specific header which does not exit on Linux. And compile as `gcc -Wall -g hw.c -o hw` – Basile Starynkevitch Oct 21 '13 at 16:38
  • 4
    `conio.h` is not a standard `.h` file in standard library. It's not defined in `POSIX` – yakiang Oct 21 '13 at 16:39
  • ok. i tried to do sudo aptitude install libc-dev g++ build-essential. But it said: No packages will be installed, upgraded, or removed. 0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 0 B of archives. After unpacking 0 B will be used. But problem did not solve.... – namco Oct 21 '13 at 17:03
  • Your issue is a sysadmin issue. Did you run `aptitude update` and `upgrade`. Please repair your system first. – Basile Starynkevitch Oct 21 '13 at 17:28
  • Yes of course i did aptitude update and upgrade – namco Oct 21 '13 at 17:31
  • Are you able to install any new package? – Basile Starynkevitch Oct 21 '13 at 18:09

5 Answers5

41

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

sudo apt-get install g++

david
  • 411
  • 3
  • 2
  • 4
    Upvoting this, but it's probably the libc6-dev package that does it. – MikeHoss Mar 24 '14 at 18:54
  • 1
    Had this problem with Mint 18.1 when I was building with Ceedling (Unity) could not find setjmp.h. Adding G++ fixed it but I agree all I needed was the dev package. – bd2357 Jun 23 '17 at 21:56
8

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:

user2229691
  • 1,099
  • 12
  • 10
7

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.

7

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.
Mike Gleason
  • 3,439
  • 1
  • 14
  • 7
0

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]

Krishna Chalise
  • 147
  • 1
  • 15