Solved

To compile and execute a C++ file in UNIX

Posted on 1999-01-28
4
172 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

770 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