LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-16-2009, 04:05 PM   #1
patient_penguin
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Rep: Reputation: 0
bash/ksh ./main: no such file or directory


Wondering if anyone has seen this before:
Running Ubuntu 9.04
gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4)

Two "C" source files - "main.c" and a function "clear.c"
Compile both to object files main.o clear.o
link to executable: main

bash> ./main
bash: ./main: No such file or directory

Question: why can't the shell bash or ksh execute this
executable?
/** NOTE: I have ./ prepended so this is not a PATH problem **/
/** Also added . to my PATH for good measure. **/

/* I did the following just to see*/

bash> file main
bash> main: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped

/** Also tried running it in the current shell **/
bash> . ./main
bash> ELF: Command not found

/** The above is interesting - thinks it's a shell-script **/

/** Also tried re-naming the executable and source files. no dice.**/

Here are the steps i'm using:
gcc -DLINUX -c main.c -I../include -I/usr/include

gcc -DLINUX -c clear.c -I../include -I/usr/include

ld -o main /usr/lib/crt1.o /usr/lib/crti.o main.o /usr/lib/crtn.o -L../lib -L/usr/lib -lc clear.o

Any help greatly appreciated..

-Patient_Penguin
 
Old 09-16-2009, 05:10 PM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by patient_penguin View Post
Wondering if anyone has seen this before:
Running Ubuntu 9.04
gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4)

Two "C" source files - "main.c" and a function "clear.c"
Compile both to object files main.o clear.o
link to executable: main

bash> ./main
bash: ./main: No such file or directory

Question: why can't the shell bash or ksh execute this
executable?
/** NOTE: I have ./ prepended so this is not a PATH problem **/
/** Also added . to my PATH for good measure. **/

/* I did the following just to see*/

bash> file main
bash> main: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped

/** Also tried running it in the current shell **/
bash> . ./main
bash> ELF: Command not found

/** The above is interesting - thinks it's a shell-script **/

/** Also tried re-naming the executable and source files. no dice.**/

Here are the steps i'm using:
gcc -DLINUX -c main.c -I../include -I/usr/include

gcc -DLINUX -c clear.c -I../include -I/usr/include

ld -o main /usr/lib/crt1.o /usr/lib/crti.o main.o /usr/lib/crtn.o -L../lib -L/usr/lib -lc clear.o

Any help greatly appreciated..

-Patient_Penguin
In a case like this, it always helps to say what experience level you have. Have you ever compiled and run a C program before? Is the problem you are having the first time you have had difficulty running a program after a compilation, or is compiling C programs a new experience for you?

It appears that most of your problems could be solved by doing it this way:

Code:
$ gcc main.c clear.c -o main
$ ./main
If this doesn't work, you should look into your system defaults for includes and resources -- much effort goes into making the compiler default to reasonable include and library paths with no fuss.
 
Old 09-16-2009, 05:17 PM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,074

Rep: Reputation: 386Reputation: 386Reputation: 386Reputation: 386
The problem sourcing the file is not starnge, the dot . (or "source") command work only with shell scripts.

For the rest, double check the output of "ldd main" to see if the required libraries are in place. Maybe you compiled them with a different version of glibc or whatever and it can't link to the current one.
 
Old 09-16-2009, 06:35 PM   #4
solarkash
LQ Newbie
 
Registered: Jun 2008
Posts: 11

Rep: Reputation: 1
Probably you need to set execution bit:

Quote:
chmod 755 main
./main
 
Old 09-17-2009, 06:10 AM   #5
patient_penguin
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks to all that have replied..

Not sure what experience level has to do with it but
can't say I'm a newbie to compiling source and linking
objects in this fashion.

Using this method to build static libraries from the object files.
Unfortunately it's my first time trying it on Linux.
(my experience is Solaris/HPUX/Realix/OSF/IRIX)

/** Execution bit is set, linkers do this by default when building executables - thanks for your suggestion here **/

/** I didn't know $. ./exe would not run an executable - proof of old dogs and new tricks.. - thanks **/

I will try the ldd main mentioned to see what this reveals - I'll also try to dump the symbol tables of obj and exe using "nm".. or whatever linux has as a replacement - thank you very much for this.
 
Old 09-17-2009, 08:16 AM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,074

Rep: Reputation: 386Reputation: 386Reputation: 386Reputation: 386
That kind of error, when you know that the file is there, is in my experience either due to some broken ldd stuff or due to fs corruption (well besides the obvious possibility, that the file is not really there, but I assume that's not the case). That's why I suggested using ldd, and if that doesn't work I'd suggest to use fsck in that volume.
 
Old 09-17-2009, 10:27 AM   #7
patient_penguin
LQ Newbie
 
Registered: Sep 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Thought of the FS corruption possibility as well.
so i moved the executable to another machine: same problem.

anyway - used the obvious work around, invoked the linker
from compiler front-end and it linked and runs fine.

Must be an ld option i'm missing, would think that standard
defaults would work but apparently not.

anyway - thanks all, problem solved.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
-bash: ./a.out: No such file or directory saritha Linux - Newbie 5 02-18-2008 09:02 PM
bash: ./configure no such file or directory VIR3NT Linux - Software 2 04-22-2006 11:04 PM
bash: cd: My: No such file or directory Doug.Gentry Fedora 2 12-05-2004 03:53 PM
bash: ./configure: No such file or directory penguin_powered Mandriva 2 10-31-2004 07:06 PM
bash: ./configure: No such file or directory gousers Linux - Software 6 09-01-2004 11:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:21 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration