LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-14-2005, 12:35 PM   #1
halfpower
Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 241

Rep: Reputation: 31
Why does GCC pre-pend ./ to my executable?


GCC prepends a "./" to my executable. I tried to rename the file with out the "./" but it didn't work. Is there anyway around this, short of making a soft link?
 
Old 12-14-2005, 01:58 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
1. You don't have you PATH set correctly. Most times folks have a PATH variable that has
Code:
:.:$HOME:
somewhere in it, usually at the beginning.

The current working directory is ./

The default output from gcc myfile is ./a.out
Code:
gcc -o myfile -Wall myfile.c
will create an executable file named myfile in the current directory. If you put a
Code:
 gcc -o /path/to/somewhere/myfile -Wall myfile.c
then myfile ends up in /path/to/somewhere
 
Old 12-14-2005, 02:07 PM   #3
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Yeah, GCC does not prepend ./ to your executable. But it is required to execute something in your current directory, assuming that your directory is not in $PATH. (Either as "." or its full name)
 
Old 12-14-2005, 02:26 PM   #4
halfpower
Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 241

Original Poster
Rep: Reputation: 31
How do I set PATH? I'm using Debian if that matters.
 
Old 12-14-2005, 03:14 PM   #5
halfpower
Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 241

Original Poster
Rep: Reputation: 31
Okay. I see that I can solve this issue if I move the executable to /usr/bin.
 
Old 12-14-2005, 03:18 PM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Add this line to the end of the file ".bashrc" in your home-directory (create if it doesn't exist):
Code:
export PATH=$PATH:.
Then, re-login.

However, for security reasons it's not recommended to add the working directory ( . ) to your PATH. Especially for root it's better not to do this.
 
Old 12-14-2005, 03:21 PM   #7
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by halfpower
Okay. I see that I can solve this issue if I move the executable to /usr/bin.
Yes, because /usr/bin already in your PATH.
It's recommended to put it in /usr/local/bin instead of /usr/bin.
 
Old 12-14-2005, 03:40 PM   #8
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

1. I think the previous posters made it very clear that gcc doesn't prepend anything to your executable, but that *YOU* need to prepend the "./" in your *COMMAND LINE* ... to *ANY* shell script or binary executable that's not in a "standard directory".

2. I think you're also clear that "/usr/local/bin" is a better "standard directory" than "/usr/bin", for the simple reason that /usr/bin should be reserved exclusively for "system stuff".

3. You're probably wondering why Linux does something as perverse as not looking in the current directory - why it doesn't look there FIRST? There are actually some very good reasons for this:

http://www.developertutorials.com/tu...512/page1.html

'Hope that helps .. PSM
 
  


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
Executable compiled w/gcc won't run brancheb Programming 5 05-16-2004 01:56 PM
gcc can't create executable Aeion Linux - Newbie 1 04-06-2004 12:03 PM
To big executable with gcc thrix Programming 8 01-22-2004 04:43 PM
i want smaller executable with gcc ! thrix Programming 6 01-22-2004 10:50 AM
Pre-Build Executable "No Such File or Directory" problem Archeress Linux - General 2 08-17-2002 08:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:05 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