Solved

To compile and execute a C++ file in UNIX

Posted on 1999-01-28
4
170 Views
Last Modified: 2010-04-02
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.
0
Comment
Question by:thenmozhia
  • 2
  • 2
4 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 1185437
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.

0
 

Author Comment

by:thenmozhia
ID: 1185438
I found Jhance answer is correct. By mistake previously I rejected his anwer. Sorry for that.

Thankyou
0
 
LVL 32

Accepted Solution

by:
jhance earned 50 total points
ID: 1185439
OK, how about we try it again.....
0
 

Author Comment

by:thenmozhia
ID: 1185440
o.k. and Thankyou so much.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now