How to run/compile a c/c++ program in Ubuntu?

Asked by RAMNATH

Dear friends,
                      I have installed gcc & g++ in but whenever I try to compile in the terminal it says that no such file exits.Here i how I did it......

$ gcc n.c
   gcc: n.c: No such file or directory
   gcc: no input files

again,
~$ gcc -o n n.c
gcc: n.c: No such file or directory
gcc: no input files

and,
~$ gcc -o n n.c
gcc: n.c: No such file or directory
gcc: no input files

I am learning c,c++ But even after 3 days of effort I am unable to solve the problem.I have specified the correct path name aswell.Any body please help me.......

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Cesare Tirabassi
Solved:
Last query:
Last reply:
Revision history for this message
Dmitry Mityugov (dmitry-mityugov) said :
#1

Hello,

It seems gcc cannot find your files. Are they listed when you run this command: ls in the same directory where you are running gcc?

Revision history for this message
RAMNATH (ram-navar) said :
#2

 Dmitry,
                My *.c file is in the same directory where I am running gcc.Here is the example,

~$ls
                       Desktop N.C Projects Ram's folder
                       Examples N.C~ ramnath
~$ gcc -o N N.c
                        gcc: N.c: No such file or directory
                        gcc: no input files

Revision history for this message
RAMNATH (ram-navar) said :
#3

Dear friend,
                Latter This took place did the following........

~$ gss n.c -o n.run
The program 'gss' is currently not installed. You can install it by typing:
sudo apt-get install libgss-dev
Make sure you have the 'universe' component enabled
bash: gss: command not found
~$ sudo apt-get install libgss-dev
Password:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libgss0 libshishi0 shishi-common
Suggested packages:
  shishi
The following NEW packages will be installed:
  libgss-dev libgss0 libshishi0 shishi-common
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 421kB of archives.
After unpacking 1249kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://in.archive.ubuntu.com feisty/universe shishi-common 0.0.30-1 [90.1kB]
Get:2 http://in.archive.ubuntu.com feisty/universe libshishi0 0.0.30-1 [205kB]
Get:3 http://in.archive.ubuntu.com feisty/universe libgss0 0.0.18-1 [61.0kB]
Get:4 http://in.archive.ubuntu.com feisty/universe libgss-dev 0.0.18-1 [65.1kB]
Fetched 421kB in 4s (93.2kB/s)
Selecting previously deselected package shishi-common.
(Reading database ... ^[[5~119669 files and directories currently installed.)
Unpacking shishi-common (from .../shishi-common_0.0.30-1_all.deb) ...
Selecting previously deselected package libshishi0.
Unpacking libshishi0 (from .../libshishi0_0.0.30-1_i386.deb) ...
Selecting previously deselected package libgss0.
Unpacking libgss0 (from .../libgss0_0.0.18-1_i386.deb) ...
Selecting previously deselected package libgss-dev.
Unpacking libgss-dev (from .../libgss-dev_0.0.18-1_i386.deb) ...
Setting up shishi-common (0.0.30-1) ...
Setting up libshishi0 (0.0.30-1) ...

Setting up libgss0 (0.0.18-1) ...

Setting up libgss-dev (0.0.18-1) ...
ramnath@ramnath-desktop:~$ gss n.c -o n.run
gss: invalid option -- o
ramnath@ramnath-desktop:~$ gss n.c -o n.run
gss: invalid option -- o
ramnath@ramnath-desktop:~$ gss n.c n.run
gss: missing parameter
Try `gss --help' for more information.
gss 0.0.18

Command line interface to GSS, used to explain error codes.

Usage: gss [OPTIONS]...

  -h, --help Print help and exit
  -V, --version Print version and exit
  -m, --major=LONG Describe a `major status' error code vaue in plain text.
  -q, --quiet Silent operation (default=off)

WHAT SHOULD I DO?

Revision history for this message
Best Cesare Tirabassi (norsetto) said :
#4

If you call your source N.C and you ask to compile n.c or N.c of course it won't find it: Linux is case sensitive.
Rename your source from N.C to n.c (personal suggestion, if you can, use a meaningful name so that you will remember what it is).

Revision history for this message
RAMNATH (ram-navar) said :
#5

Thanks a loooootttt1
its working but I have got another one to solve.
the header file is not been recognized , I know there fore that I have no library files, How can i include them?
see the example:

#include<stdio.h>
#include<conio.h>
int main()
{
 int a,b;
 clrscr();
 scanf("%d",&a);
 scanf("%d",&b);
 printf(" %d",a*b);
 getch();
}

 gcc n.c -o n.run
n.c:2:18: error: conio.h: No such file or directory

Revision history for this message
Cesare Tirabassi (norsetto) said :
#6

Indeed you have to install the base library (libc6-dev). You can do that directly or with the build-essential metapackage.

Revision history for this message
Cesare Tirabassi (norsetto) said :
#7

Sorry, rereading your question the problem is not stdio.h but conio.h, which is indeed not supported by gcc (if I remember it correctly it was a borland proprietary implementation not even iso compliant).
For which function do you need to use it, getch?
If so, you can consider using the getchar function (defined in stdio.h).

Revision history for this message
RAMNATH (ram-navar) said :
#8

Thanks A lot for spending your precious time in helping me.
_________________________________________________________________
Palate Teasers: Straight from Master Chef!
http://content.msn.co.in/Lifestyle/Moreonlifestyle/LifestylePT_101106_1530.htm

Revision history for this message
Simos Xenitellis  (simosx) said :
#9

Ramnath, this question appears to be still open. Could you please change the status to Solved? Thanks.

Revision history for this message
RAMNATH (ram-navar) said :
#10

THANK A LOT FOR Cesare Tirabassi & Dmitry Mityugov!!!!!!!!!!!!

Revision history for this message
RAMNATH (ram-navar) said :
#11

Thanks Cesare Tirabassi, that solved my question.

Revision history for this message
dhrubo (saquib-mail) said :
#12

i used gcc test.c -o a
it compiled the "test.c" file n a "a" executable file is created.
now how can i run the file to see the output of the code ???

Revision history for this message
marcobra (Marco Braida) (marcobra) said :
#13

Type:

./a

or change permission of file
chmod 700 a

and run it
./a

Hope this helps

Revision history for this message
Pravah Shukla (pravah101shukla) said :
#14

Instead change the permission of the file using
chmod 744 a
well it is recommended to generate a.out file
well now run it by typing
./a

do make sure the directory where the file is there

Revision history for this message
navraj (navraj19) said :
#15

type ./a.out and there will be a output for sure