Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to execute a .cpp file while contains the #include <conio.h> header file, but while executing I'm getting the following error:

"program.cpp:4:20: fatal error: conio.h: No such file or directory compilation terminated."

I've tried with the curses.h header file also, but still showing the same error as above. I need to use this header file because I'm using the clrscr() and getch() functions which require it.

Can anybody tell me how to rectify this problem?

share|improve this question

closed as off-topic by Gilles, slm, devnull, Thomas Nyman, Anthon Apr 29 '14 at 4:11

  • This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

Did you install build-essential? – Danatela Apr 28 '14 at 4:48
conio.h is not a C++ function. It is a Microsoft function. As such, you'll struggle to find it on Ubuntu. – Lightness Races in Orbit Apr 28 '14 at 10:24
@LightnessRacesinOrbit conio.h is Microsoft? Odd, I distinctly remember Borland Turbo C 2.0 (at least) having it, and that was decidedly not Microsoft. – Michael Kjörling Jul 14 '14 at 12:48
@MichaelKjörling It stemmed from DOS compilers, yes. Everything you need to know is on the Wikipedia page. – Lightness Races in Orbit Jul 14 '14 at 13:48
@LightnessRacesinOrbit Actually, I remember those days fairly well. But thanks for the link anyway. – Michael Kjörling Jul 15 '14 at 7:23

The conio.h -- clrscr() -- getch() path is not followed in Linux. By this, I mean, you need not use conio.h and it's functions on a Linux platform.

1. clrscr() : Since you are planning on using ncurses, there is a clear() function included in it, which clears the screen. Just replace clrscr() with clear().

2. getch() : Linux provides a wide array of such functions like gets, fgets, scanf and so on.

3. ncurses : In Linux, ncurses does not depend on conio at all. So this is again unnecessary.

clrscr() and getch() are both part of conio.h. It is primarily used in MS-DOS based compilers. In Linux, they are kinda unnecessary.

share|improve this answer
@slm - Most Linux programmers do not bother with conio.h. And when I say "by default", Please note that conio is not part of the C standard library, ISO C nor is it defined by POSIX. So basically, it is not native in Linux. And if you go through the question, conio + clrscr + getch combination clearly indicate it was a program originally written on some windows based compiler, like TurboC. I stand by my answer. Conio is not something native to Linux. – Stark07 Apr 28 '14 at 6:06
Your 1st sentence is the key item. This situation would seem to be cpp code that was developed for Windows and the OP is now compiling it on Linux. So they have 2 options. Either bring this library into the include path or go through the code base and do a replacement on calls. – slm Apr 28 '14 at 6:18
There's not "replacement" as such. clrscr and getch are unnecessary. And as for clrscr, The program already is going to use ncurses, which has clear() for this purpose. – Stark07 Apr 28 '14 at 6:30
You have to do something to the code base, otherwise it will not compile. That is what I meant! – slm Apr 28 '14 at 6:31
We are saying the same thing now. They can either use the library or address the missing functions in their code base. Which ever is easier to them is their choice, we are merely giving them the options available! – slm Apr 28 '14 at 6:34


You basically have 2 choices on how to proceed. You can either install a package that includes conio.h + its library as I describe below or you can use ncurses.h + its library and swap out and/or remove function calls that depend on it as @Ashish Kulkarni describes in his answer. Either option is viable and is up to the developer/implementer to decide which is the "correct" path.

The conio.h header + library for C/C++ is not something you'll typically find as being installed by default with most Linux distros. At least not the ones that I'm familiar with Fedora/CentOS/RHEL/Debian/Ubuntu.

NOTE:: Also the use of ncurses.h is not appropriate here either, since that library will likely not include any of the functions that you're looking for (clrscr(), getch(), etc.) since your .cpp file would seem to be coming from a Windows environment originally.

However you have the option with Linux to install packages from centrally managed repositories. Looking for a package that includes conio.h on my Fedora system I turned up this package. I realize you're on Ubuntu but on Fedora the package is called libconio that provides exactly the libraries that you're looking for.

$ yum info libconio.i686
Loaded plugins: auto-update-debuginfo, changelog, langpacks, refresh-packagekit
Available Packages
Name        : libconio
Arch        : i686
Version     : 1.0.0
Release     : 3.2
Size        : 6.3 k
Repo        : rpm-sphere
Summary     : Implementation of conio.h functions
License     : GPL
Description : libconio is an implementation of conio.h functions that some 
            : DOS and Windows compilers provide. It's purpose is to allow 
            : developers to use functions like getch, getche, textcolor and 
            : others in a linux environment.

Looking on a Ubuntu system I have there's a similar package called elks-libc that also contains conio.h.

$ apt-cache show elks-libc
Package: elks-libc
Priority: optional
Section: devel
Installed-Size: 651
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Juan Cespedes <cespedes@debian.org>
Architecture: all
Source: linux86
Version: 0.16.17-3.1ubuntu3
Replaces: bcc (<< 0.14.9), linux86
Recommends: bcc (= 0.16.17-3.1ubuntu3)
Conflicts: linux86
Filename: pool/main/l/linux86/elks-libc_0.16.17-3.1ubuntu3_all.deb
Size: 214574
MD5sum: 75d87d8c2c906579ec84624fff93d76d
SHA1: 5cd6d3b9c5a881ad5fcdcffbd5a075761b017731
SHA256: 57bee73becbeae5dc2bc4cd859c13dc065e4a49472d876225e3e37fd6538feb2
Description-en: 16-bit x86 C library and include files
 This is the C library used to compile with bcc. It includes all the
 headers and static libraries needed to build 16-bit applications,
 for Linux/8086, Linux/i386 and DOS .COM executables.
Description-md5: 2da04d6881989db1f4a11df4a992c06f
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 18m

And here's the file:

$ apt-file list elks-libc | grep conio.h
elks-libc: /usr/lib/bcc/include/conio.h

So you can simply install this package to get the header file + libraries that your application requires to compile.

$ sudo apt-get install elks-libc

NOTE: You may need to adjust your include path to gcc to pick this header file up.

elks-libc is only for 8088 Intel processors

As mentioned in the comments, elks-libc is intended for use on system's that are targeting the Intel 8088 CPU. You can instead download libconio.h from the SourceForge project titled: Linux c++ implementation of conio.h. You'll have to install it manually but it shouldn't be too difficult to do this.

Simple Linux implementation of Borland's conio (conio.h) library. It uses Ncurses. It includes most functions required to write a basic application using conioh (i.e. getch(), cprintf(), puts() and more).

You can also get the entire libconio project's source from this SourceForge project titled: libconio and unpack it.

Details on doing this as well as building it and compiling it are covered in this tutorial titled: How to use with GCC.

share|improve this answer
Why would anyone want to use conio.h on Linux? – enedil Apr 28 '14 at 5:32
@enedil - I think the description says everything you need to know.."libconio is an implementation of conio.h functions that some DOS and Windows compilers provide. It's purpose is to allow developers to use functions like getch, getche, textcolor and others in a linux environment." – slm Apr 28 '14 at 5:33
@enedil - if you've ever written programs that are multi OS then you'd understand. We write them at my day job and have to provide a lot of #ifdef'ing to get around differences b/w Visual Studio & gcc. The existence of these libraries is to mitigate having to do a lot of this. – slm Apr 28 '14 at 5:36
elks-libc is only to compile 8088 programs with bcc, not to compile programs for a “normal” Linux. conio.h is a DOS thing. Ncurses is the unix equivalent. If you want something cross-platform, use an ncurses port under Windows. – Gilles Apr 28 '14 at 21:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.