Solved

To compile and execute a C++ file in UNIX

Posted on 1999-01-28
4
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

739 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