Link to home
Start Free TrialLog in
Avatar of thenmozhia
thenmozhia

asked on

To compile and execute a C++ file in UNIX

I compiled a c++ file in Unix as gcc filename.cc. It didn't give me any error. But when I type a.out next it is saying file not found or bad command. The same thing is happening when I try to compile and run a C file giving the command cc filename.c and a.out.

Kindly help me.
Avatar of jhance
jhance

Try this:

/a.out

My guess is that you're logged in as root and the default PATH for root is NOT to include the current directory or ".".  By saying ./<program_name> you're telling the shell to run the a.out in the current working directory.

You can also compile with the -o option like this:

gcc filename.c -o filename

so the output will go to filename instead of to a.out.

Avatar of thenmozhia

ASKER

I found Jhance answer is correct. By mistake previously I rejected his anwer. Sorry for that.

Thankyou
ASKER CERTIFIED SOLUTION
Avatar of jhance
jhance

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
o.k. and Thankyou so much.