LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash/ksh ./main: no such file or directory (https://www.linuxquestions.org/questions/linux-newbie-8/bash-ksh-main-no-such-file-or-directory-755714/)

patient_penguin 09-16-2009 03:05 PM

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

lutusp 09-16-2009 04:10 PM

Quote:

Originally Posted by patient_penguin (Post 3685735)
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.

i92guboj 09-16-2009 04:17 PM

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.

solarkash 09-16-2009 05:35 PM

Probably you need to set execution bit:

Quote:

chmod 755 main
./main

patient_penguin 09-17-2009 05:10 AM

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.

i92guboj 09-17-2009 07:16 AM

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.

patient_penguin 09-17-2009 09:27 AM

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.


All times are GMT -5. The time now is 02:17 PM.