LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-25-2008, 12:37 AM   #16
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled

Quote:
Originally Posted by xologist View Post
I thought the a.out was an executable. However it isn't executing. The question for the Guru's here is how is the compiled a.out file executed? It seems like a stupid question. Supposedly from the textbook on C it is a simple matter of typing a.out. That only results in the "command not found."
When you specify an executable on the command line, the shell looks for it in the directories listed in the PATH environment variable. If it isn't in one of those directories, then you'll get that error. Without putting the current directory in your PATH, you just need to give the full path to the executable, which using shorthand is just "./a.out" ("." is shorthand for the current directory).
 
Old 08-25-2008, 01:36 AM   #17
xologist
LQ Newbie
 
Registered: Aug 2008
Location: Pensacola, Fl. Lived in MD, DC and VA area for years
Distribution: Debian Etch
Posts: 17

Original Poster
Rep: Reputation: 0
First an apology then a grand thank you Nylex

Nylex I want to apologize for not putting the source within the code tags as you requested. Quite frankly I don't understand how they work. Linux/Unix does things with text that Microslop hasn't even thought of. I am just a simple minded Ph.D. Psychologist who hacks his way around. Ninety-nine percent of the time I do so solo with the assistance of www documnetation. I shall master the code tags because the chaps like you who are wizards need to have their information in a format they can quickly use to sort out the problem(s) at hand.

I did the ./a.out notation in the command line as you described and walla success. Thanks to you and the others I can move on and do the more advanced exercises and see if I can learn some C.

My expertise is with Microsoft SQL (T-SQL) which I used a great deal to organize research data for the Department of Veteran Affairs. I have MySQL loaded as well as Apache on my Linux box and I hope to set up some databases and learn to write some CGI and php. I see you are a Ph.D. student. What are you doing your dissertation on if I may ask?

Again thank you so very much and I will learn the code tags for the next round.

Jim
 
Old 08-25-2008, 02:06 AM   #18
xologist
LQ Newbie
 
Registered: Aug 2008
Location: Pensacola, Fl. Lived in MD, DC and VA area for years
Distribution: Debian Etch
Posts: 17

Original Poster
Rep: Reputation: 0
A go at code tags and a request to explain why code tags.

Code:
#include <stdio.h>
int main(void)    /* a simple program jwf aug 9,2008 */
{
	int num;    /* define a variable called num */
	num = 1;    /* assign a value to num  */

	printf("I am a simple "); /* use the printf() function */
	printf("computer.\n");
	printf("My favorite number is %d because it is first. \n",num);
	return 0;
}
Is this it gents? The code tags that you requested? I don't understand their use. I read they are like html from LQ documentation but how do you use them to help me sort out the problem. In my case it (the problem) was the EOF line inserted by VI when I completed the text of the source code and entered the command mode and issued the :wq command (save and quit).

Sorry I don't want to be a pain in the arse. But I do want to understand.

Jim
 
Old 08-25-2008, 02:28 AM   #19
xologist
LQ Newbie
 
Registered: Aug 2008
Location: Pensacola, Fl. Lived in MD, DC and VA area for years
Distribution: Debian Etch
Posts: 17

Original Poster
Rep: Reputation: 0
A go at code tags and a request to explain why code tags.

Code:
#include <stdio.h>
int main(void)    /* a simple program jwf aug 9,2008 */
{
	int num;    /* define a variable called num */
	num = 1;    /* assign a value to num  */

	printf("I am a simple "); /* use the printf() function */
	printf("computer.\n");
	printf("My favorite number is %d because it is first. \n",num);
	return 0;
}
Is this it gents? The code tags that you requested? I don't understand their use. I read they are like html from LQ documentation but how do you use them to help me sort out the problem. In my case it (the problem) was the EOF line inserted by VI when I completed the text of the source code and entered the command mode and issued the :wq command (save and quit).

Sorry I don't want to be a pain in the arse. But I do want to understand.

Jim
 
Old 08-25-2008, 03:07 AM   #20
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Yes, like that. All they really do is to help make code more readable. I suppose it doesn't really matter too much for small programs like yours, but definitely for longer ones it makes a difference. Now, if only line numbers could be shown .

Psychology, eh? Some of that stuff is pretty interesting, I find. As for what I'm doing, solar-terrestrial physics. I'm currently looking at sunspot oscillations and am interested in using them as a tool for solar coronal seismology (basically, using oscillations to study the structure of the sun), though we're planning to do other stuff as well.
 
Old 08-25-2008, 07:22 AM   #21
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
When you try to execute a.out, you will probably need to explicitly state that it is in the present directory by prefixing "./" to it. i.e.
Code:
./a.out
Sometimes this is not necessary, but with most default configurations it is. It all depends on the contents of your PATH environment variable.

When you type in a command, the shell checks the first word of the command to see if it is a shell-internal command, alias or function, and if not, it looks in each directory listed in the PATH to see if there is an executable file with that name. If one is found, it is executed.

You can examine your PATH like this:
Code:
echo $PATH
It is a colon (":") separated list of directories to search for commands.

You can do this to check it more easily:
Code:
echo $PATH |tr ":" "\n"
If you see "." as one of the entries there, the present working directory will be searched, else it will not and you will have to prefix ./ to execute files from the present working directory (if the working directory is not one of the other directories in the PATH).

For good security reasons the present working directory, "." should not be in the PATH, or at least be the last item in the PATH. Many Linux distros in their default configuration don't include "." in the PATH for normal user accounts (and *hopefully* should never do it for root accounts).

Last edited by matthewg42; 08-25-2008 at 07:23 AM. Reason: should not allow DOS-styte "cwd" pollute *nix discussions when I mean "pwd"
 
Old 08-25-2008, 08:16 AM   #22
xologist
LQ Newbie
 
Registered: Aug 2008
Location: Pensacola, Fl. Lived in MD, DC and VA area for years
Distribution: Debian Etch
Posts: 17

Original Poster
Rep: Reputation: 0
Piece by Piece

Nylex; Matthew many thanks for taking the time and effort to help with this C compiler problem. I should also make sure that Knudfl gets his due as he realized I didn't have the proper library installed. I wish there was an easier way to get back to all the threads instead of having to do the browser back button to review all that was said and done.

It is taking me some time to learn and relearn various aspects (sometimes idosyncricies) of Linux. I see from my Linux box journal I encountered ./ while experiencing difficulty executing a bash script to collect information on my box's new sound card and configuration about two weeks ago and again that was a PATH issue. Perhaps I should consider changing the environment variable. I can understand the security risk you described Matthew and encountered discussion on that in Osamu Aoki. During the final resolution, prior to Nylex's thread which provided the solution, the thought crossed my mind. However I was more inclined to think it was a permission issue. In fact I did a chmod to no avail on the a.out.file. Furthmore I understand I must rename the a.out file if I want to retain it as the compiler will wipe it when I compile the next C erercise. I also find myself wondering if these compiled source files will run on other systems like MS.

In closing my thanks again. BTW as a Ham radio operator sun spots are quite important and I understand we little to no sun spots these days.

Jim
 
Old 08-25-2008, 08:29 AM   #23
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by xologist View Post
Nylex; Matthew many thanks for taking the time and effort to help with this C compiler problem.
No problem.

Quote:
Furthmore I understand I must rename the a.out file if I want to retain it as the compiler will wipe it when I compile the next C erercise. I also find myself wondering if these compiled source files will run on other systems like MS.
You can use gcc's -o option to specify the output file name, e.g.

gcc test.c -o test

will create an executable named "test", rather than "a.out". As for whether or not these executables will run under Windows or other operating systems, no they won't. Other operating systems use different "formats" (I'm not an expert on this), but basically the answer is no , at least not without help (e.g. you can run some Windows programs under Linux using WINE).

Quote:
BTW as a Ham radio operator sun spots are quite important and I understand we little to no sun spots these days.
It's off-topic, but I feel like responding to this. Yes, the sun has an 11 (or 22) year cycle of activity where at solar minimum, we see few sunspots and the opposite is true at maximum. I believe a new cycle was meant to have started some time ago, but the sun still appears to be at minimum. Perhaps we're going through something like the Maunder minimum, but who knows?
 
Old 08-25-2008, 09:13 AM   #24
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
To execute : Command in a terminal :
'cd path-to-where-a.out-is' or just
place 'a.out' in /home/xologist/
and execute with ' ./a.out '
where the . dot means the current
directory.

Regards
 
Old 08-27-2008, 01:33 AM   #25
xologist
LQ Newbie
 
Registered: Aug 2008
Location: Pensacola, Fl. Lived in MD, DC and VA area for years
Distribution: Debian Etch
Posts: 17

Original Poster
Rep: Reputation: 0
Final Analysis

Gents (Matthew, Nylex and Knudfl) I had a go at the suggestions each of you responded with and read with interest your say on the topics at hand. Consequently I've added a bit more information to what lies inbetween my ears with respect to gcc and Linux and of course bash. It appears that all of these are intertwined. Keeping my Linux journal up to date allows me to at least keep track of the territory I cover and the outcome of solutions. I do take all of this quite seriously.

Code:
/* Attempts to examine environment by both methods suggested
by Mathhew and Nylex produced the same results */

/* results */
echo $PATH
/usr/local/bin:/usr/bin/:/bin:/user/games

echo $PATH | tr ":" " \n"
/usr/local/bin:
/usr/bin:
/bin:
/user/games:
Security is intact. My home directory ( /home/xologist) should be included in the $PATH

Knudfl I used the gcc command to name the output of compiled C program with the "-o" option.

Again I truely thank each of you for helping me along and for helping to solve the gcc problems. Now I have the ability to compile the C programs presented in the text book, do the exercises and take the tests that teach the concepts I will neeed to master so I can write my own programs. Perhaps I can pester you again if I run into problems as I continue configuring this Linux test box.





Regards,

Jim Frock
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Gcc Problem: I Cannot Compile Simple C++ Programs ankurgarg Linux - Software 2 06-13-2008 05:22 AM
RTAI - Can't compile simple.c with gcc (hello world program) mario-vallejo Linux - General 1 04-23-2008 08:13 AM
Debian Etch Won't compile drivers Person_1873 Linux - Wireless Networking 7 11-12-2007 11:04 PM
LXer: Installing Simple Invoices On Debian Etch LXer Syndicated Linux News 0 08-24-2007 02:30 AM
can't compile simple C++ programs on Suse 9.1 after installing gcc cyclebain Linux - Software 9 07-04-2007 08:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration