LinuxQuestions.org
Help answer threads with 0 replies.
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-06-2012, 09:35 AM   #1
krafczyk
LQ Newbie
 
Registered: Mar 2012
Posts: 7

Rep: Reputation: Disabled
bash can't find executable which exists.


This is a rather complex situation and I'll happily accept somebody telling me a better way to do any part of this.

1. I have to use an old version of gcc (4.1), so I built and installed it into a subdirectory which does not interfere with the versions which I've had ubuntu install. (4.4,4.5,4.6)

2. Upon using this compiler by adjusting the /usr/bin/g{cc,++,fortran} links to the gcc 4.1 versions, I found that many times the wrong libstdc++ was being linked against causing symbol lookup errors. To solve this problem (and avoid using LD_LIBRARY_PATH and LD_RUN_PATH) I decided to use the a gcc specs file to add the correct run path at the linking stage. I did this by using a perl script to add the spec file argument before all other arguments passed to the various gcc compilers.

Perl script:

Code:
#!/usr/bin/perl

exec('/usr/local/src/gnu/gcc/4.1/install/bin/gcc-4.1','-specs=/usr/local/src/gnu/gcc/4.1/install/bin/specs_file',@ARGV);
Specs file:

Code:
%rename link  old_link
 
*link:
-rpath=/usr/local/src/gnu/gcc/4.1/install/lib64 %{old_link}
3. Now for the problem. When I try to compile a simple hello world test,

test program:

Code:
#include "stdio.h"
int main()
{
        printf("Hello world!");
        return 0;
}
I find that I cannot execute the output './a.out' because bash thinks it doesn't exist! Below I've attached several diagnostic commands which show that a.out compiled correctly, exists, it's linked properly and yet bash won't execute it. I've also included two commands which I've read can help diagnose the problem, but that I don't really understand what they say, and am hoping someone else who reads this will understand.

Code:
matthew@sibelius:~$ gcc comptest.c
matthew@sibelius:~$ ./a.out
bash: ./a.out: No such file or directory
matthew@sibelius:~$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, not stripped
matthew@sibelius:~$ ldd a.out
	linux-vdso.so.1 =>  (0x00007fff4fdff000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5f168d8000)
	/lib/ld64.so.1 => /lib64/ld-linux-x86-64.so.2 (0x00007f5f16cbb000)
matthew@sibelius:~$ hd a.out | head
00000000  7f 45 4c 46 02 01 01 00  00 00 00 00 00 00 00 00  |.ELF............|
00000010  02 00 3e 00 01 00 00 00  a0 03 40 00 00 00 00 00  |..>.......@.....|
00000020  40 00 00 00 00 00 00 00  88 09 00 00 00 00 00 00  |@...............|
00000030  00 00 00 00 40 00 38 00  07 00 40 00 1c 00 19 00  |....@.8...@.....|
00000040  06 00 00 00 05 00 00 00  40 00 00 00 00 00 00 00  |........@.......|
00000050  40 00 40 00 00 00 00 00  40 00 40 00 00 00 00 00  |@.@.....@.@.....|
00000060  88 01 00 00 00 00 00 00  88 01 00 00 00 00 00 00  |................|
00000070  08 00 00 00 00 00 00 00  03 00 00 00 04 00 00 00  |................|
00000080  c8 01 00 00 00 00 00 00  c8 01 40 00 00 00 00 00  |..........@.....|
00000090  c8 01 40 00 00 00 00 00  0f 00 00 00 00 00 00 00  |..@.............|
matthew@sibelius:~$ strace ./a.out 2> ls.t; cat ls.t
execve("./a.out", ["./a.out"], [/* 38 vars */]) = -1 ENOENT (No such file or directory)
dup(2)                                  = 3
fcntl(3, F_GETFL)                       = 0x8001 (flags O_WRONLY|O_LARGEFILE)
close(3)                                = 0
write(2, "strace: exec: No such file or di"..., 40strace: exec: No such file or directory
) = 40
exit_group(1)                           = ?
So please, can someone tell me what is going wrong here?
 
Old 08-07-2012, 05:49 AM   #2
Sidicas
Member
 
Registered: Apr 2004
Distribution: Debian GNU/Linux
Posts: 47

Rep: Reputation: 6
I had this really wonky thing happen to me when I upgraded from Debian Squeeze to Debian Wheezy... The dist-upgrade finished, I did a reboot, only to find that I couldn't execute anything in the current directory even though the files were chmod'd to be executable. It just couldn't find the file in the current directory even with ./

I could only execute things if I typed in the fully qualified path (/home/david/test.sh). I did another apt-get update and apt-get dist-upgrade.. Installed a bunch more stuff, rebooted and after that it was fixed.. Sorry, I'm sure that's probably not much help to you.

The only thing of this that still remains is that if there is an executable for a difference architecture in the current folder, and even if it's set as executable, the filesystem simply pretends that it doesn't see it.. This is still the case in Debian wheezy and I'm not sure what to make of it.. I want to file a bug, but then again, I realized that the executable I was running was compiled for a different architecture (AMD64 executable on an i386 system) which I guess would just segfault anyway.

I'm positive that in Debian Lenny (years ago), it would try to run it no matter what and then just segfault or throw an error. Now it just pretends that it doesn't see the file, if the file is executable and for a different architecture. It gives a very confusing error message saying it can't find the file when it's clearly right there in the folder and executable.

Have you tried adding both AMD64 and i386 to your architecture? Debian is moving towards "multi-architecture" and looking to get rid of the ia32-libs package which is ridiculously large and full of redundant libs. This might be something related to the move to MultiArch as a *LOT* of libs are getting shuffled around during this transition.


Such strange stuff.. Hope that helps... Or at the very least puts you on the right path to finding a solution.. Maybe there is nothing wrong with your binary and the problems is with your distro installation.

Last edited by Sidicas; 08-07-2012 at 06:05 AM.
 
Old 08-07-2012, 08:54 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,420
Blog Entries: 4

Rep: Reputation: 3373Reputation: 3373Reputation: 3373Reputation: 3373Reputation: 3373Reputation: 3373Reputation: 3373Reputation: 3373Reputation: 3373Reputation: 3373Reputation: 3373
Remember that the file, a.out or otherwise, must be marked as executable.
 
Old 08-08-2012, 05:57 PM   #4
impert
Member
 
Registered: Feb 2009
Posts: 282

Rep: Reputation: 54
This sounds like a 32-bit app on a 64-bit machine problem. If so,
this link:
Running 32-bit applicatiions on 64-bit GNU/Linux Debian should help.

Last edited by impert; 08-08-2012 at 05:58 PM. Reason: typo
 
Old 08-08-2012, 09:34 PM   #5
krafczyk
LQ Newbie
 
Registered: Mar 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks for the responses, but unfortunately neither can be the solution to my problem..

I'm running a 64bit system, and the gcc 4.1 compiler I'm using is built for 64 bit compilation. I did not add cross-compilation support.

In addition, you may see with the output of the following commands that the output of gcc is of course set to be executable.

Code:
matthew@sibelius:~$ gcc comptest.c 
matthew@sibelius:~$ ./a.out 
bash: ./a.out: No such file or directory
matthew@sibelius:~$ ls -l | grep a.out
-rwxrwxr-x  1 matthew matthew     6197 Aug  9 03:33 a.out
matthew@sibelius:~$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, not stripped
matthew@sibelius:~$ ldd a.out
	linux-vdso.so.1 =>  (0x00007fffc994b000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f85940c3000)
	/lib/ld64.so.1 => /lib64/ld-linux-x86-64.so.2 (0x00007f85944a6000)
 
Old 08-09-2012, 01:21 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,925

Rep: Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631Reputation: 2631
I think maybe this would be better off in the Programming Forum, given what you are asking.
You can use the Report button to ask the Mods to move it.
 
  


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
library exists but can not be find mahmoodn Linux - General 4 07-26-2012 06:24 PM
[SOLVED] Bash command to find out if user exists brgsousa Linux - Software 3 01-20-2011 02:13 PM
Bash Help: Check if file exists richinsc Programming 6 01-09-2009 01:27 PM
python: how to tell if an executable exists? BrianK Programming 5 06-19-2008 01:02 AM
bash check folder exists zerocool22 Programming 22 06-01-2008 08:53 AM

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

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