The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
In C Program, determine if job is running BCarlson High Level Programming 12 07-16-2006 09:05 AM
running a program for a specified time prosputko High Level Programming 3 07-06-2005 10:39 AM
running dos program from unix server rkap UNIX for Dummies Questions & Answers 1 04-06-2005 07:48 AM
Running a program perleo UNIX for Dummies Questions & Answers 3 08-23-2002 07:34 AM
Running a compiled Program Krebsbac High Level Programming 2 09-07-2001 01:39 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-11-2002
Registered User
 

Join Date: Jul 2002
Posts: 1
running a c/c++ program in unix

This is not a question, but rather a simple how-to for
programmers who are new to the UNIX environment.

I too,am new to UNIX.
First I developed a few programs on my box and perfected them
until they were satisfactory for execution.

Problem was however, that once i compiled and all that,
it occured to me, that i was new to Unix and had no freakin
clue about how to run my apps from the command-line.

I couldn't for the life of me figure out how in the !$#@ to do this.

To experienced users, this is probably 'duh!' however, to a new
user like myself, this was all frustrating.

I spent a long time working on my little program and assumed that if it works it would run. Makes sense to me.
---------
Well, i was very wrong, and after i compiled my source file "myprogram.c" with the GNU CC compiler using the line:

cc myprogram.c

then another file appeared, called:

a.out

This was because i didn't specify a name for my program.

Having very little patients with the available documentation, I found nothing about running a program once you've created it.

So i tried typing my programs name in:

a.out [ENTER]

No good, instead i get a reply back saying:

a.out: Command not found.

I just wanted my freakin program to run.

Well, good news, it 'turns out' that prefixing the programs name with "./" works.

--thats a dot, a slash and then the programs path and name

so finally i entered:

./a.out [ENTER]

and voila! the darn thing worked.

If this seemed a bit long winded, it was.
I just hope this helps someone in the future.

late,
kray
__________________
na
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-11-2002
Registered User
 

Join Date: Jul 2002
Location: void
Posts: 53
You can get around with a solution over this. Try including the following line in your ~/.profile
Code:
export PATH=.:$PATH
That's because, when you try to execute a program, the shell looks only into the directories specified in the PATH environment variable. Since "." (the current directory) was not specified in the PATH, the shell never looked into your current directory. Hence, you had to specify the full relative path (./a.out), and it worked.
Reply With Quote
  #3 (permalink)  
Old 07-12-2002
killerserv's Avatar
Unix Predator
 

Join Date: Dec 2000
Location: Phoenix, AZ
Posts: 670
More better and easier way if you could add in -o option upon compiling.

gcc -o myprogram.c myprogram

and you could execute ./myprogram easily
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0