![]() |
| | #1 |
| Registered User Join Date: Sep 2007
Posts: 10
| ld: No such file or directory I am writing a program in x86 asm, using nasm syntax, and using opengl and sdl. I assemble my program with: nasm -f elf main.asm and link with: ld -o main main.o /usr/lib/libGL.so /usr/lib/libGLU.so /usr/lib/libSDL.so so far so good. It produces an executable with no issues. However, when I try to run it with ./main It says "No such file or directory" What is going on here? When I do ls, main shows up. Thanks!! |
| kerryhall is offline | |
| | #2 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,710
| > It produces an executable with no issues. It may have produced a file, but how do you know it's executable? If you do 'ls -l', does the file have the 'x' permission bits set? Can you post the actual terminal session. Perhaps there is a typo in what you typed which is not reflected in your post. |
| Salem is offline | |
| | #3 |
| Registered User Join Date: Sep 2007
Posts: 10
| Here is the session: kerry@BigOwl:~/Programming/x86_asm/extern_func_03$ ls main.asm main.asm~ makefile makefile~ kerry@BigOwl:~/Programming/x86_asm/extern_func_03$ make nasm -f elf main.asm ld -o main main.o /usr/lib/libGL.so /usr/lib/libGLU.so /usr/lib/libSDL.so kerry@BigOwl:~/Programming/x86_asm/extern_func_03$ ./main bash: ./main: No such file or directory kerry@BigOwl:~/Programming/x86_asm/extern_func_03$ ls -l total 24 -rwxr-xr-x 1 kerry kerry 3009 2007-09-02 02:42 main -rw-r--r-- 1 kerry kerry 1585 2007-09-02 02:42 main.asm -rw-r--r-- 1 kerry kerry 1581 2007-09-02 02:05 main.asm~ -rw-r--r-- 1 kerry kerry 1760 2007-09-02 02:42 main.o -rw-r--r-- 1 kerry kerry 364 2007-09-02 02:41 makefile -rw-r--r-- 1 kerry kerry 364 2007-09-02 01:45 makefile~ kerry@BigOwl:~/Programming/x86_asm/extern_func_03$ I think it's some weird bug with ld, but maybe I am not linking right? It just doesn't make sense. ls can find the file, but bash can't. Thanks! |
| kerryhall is offline | |
| | #4 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,710
| Can you do 'ls -lb' in case make is generating a file which only looks like 'main', but in fact contains invisible characters. The -b option will show these up. If this is the case, then you need to carefully inspect your makefile using an editor which will reveal such invisible characters. Also, try typing './m' then pressing the tab key to cause bash to attempt it's own filename completion. If it comes back with something looking like './main', then press enter and see if that runs the program. |
| Salem is offline | |
| | #5 |
| Registered User Join Date: Sep 2007
Posts: 10
| ls -lb gives the same result as ls -l and ./m tab causes it to auto complete with ./main (but still giving me the same error when i run it!) thanks! |
| kerryhall is offline | |
| | #6 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Have you tried giving the file a different name? I don't think "main" is some sort of reserved name, but worth a try. It may be that it's something else going wrong (and the error message is a bit misleading). Try "strace ./main" - post the part towards the end if you're not familiar with "strace" output (the last several lines will have to do with printing the "file not found" error message - that's not the really interesting bit, but what happens before that for several lines would be). Also, if there's a space or some such at the end of the name, such as "main ", then it would stop at "main" when auto-expanding, because it's ambiguous between "main ", "main.c" and "main.o" for example. -- Mats |
| matsp is offline | |
| | #7 |
| Registered User Join Date: Sep 2007
Posts: 10
| The file definitely exists, I have tried changing the name and everything. Here is the output from strace: Code: kerry@BigOwl:~/Programming/x86_asm/extern_func_03$ strace ./main
execve("./main", ["./main"], [/* 31 vars */]) = -1 ENOENT (No such file or directory)
dup(2) = 3
fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
fstat64(3, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f13000
_llseek(3, 0, 0xbf910a04, SEEK_CUR) = -1 ESPIPE (Illegal seek)
write(3, "strace: exec: No such file or di"..., 40strace: exec: No such file or directory
) = 40
close(3) = 0
munmap(0xb7f13000, 4096) = 0
exit_group(1) = ?
Process 13595 detached
Thanks! |
| kerryhall is offline | |
| | #8 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| But your strace clearly shows that the OS doesn't think your file exists!! The thought I had was that it was somehow a shared library or some such that didn't exist. Try this: "mv main blah" - if that shows the file doesn't exist, then it's certainly something up with the filename. -- Mats |
| matsp is offline | |
| | #9 |
| Registered User Join Date: Sep 2007
Posts: 10
| mv works. every file manipulation tool, such as ls, mv, cp, works fine on it. is this a bug with linux?? |
| kerryhall is offline | |
| | #10 | |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Quote:
It seems from strace that it's simply not finding the "main" file - which means to me that it's "not there" in the filesystem in general. Unless of course some security scheme is saying "don't let this user run anything" - quite often, the error codes from such security schemes are "obfuscated" to hide that it's the security system saying you can't do this - instead of saying "You are not allowed to do this", it says "the file doesn't exist", that way you don't KNOW that it's the security system that is causing the problem. So does the new file (blah or whatever) work to run? If you copy, say, grep to main, does it work then?, using "cp /usr/bin/grep main" (or similar). Can you build a simple hello program? Anoter option is that the file is refused to load (and the kernel doesn't distinguish on a fine-grain enough) because there's something else wrong with your load process. Could you dump with "objdump -d" the first few lines of assembler, and compare that to for example a C program (grep will work) to see if there's some noticable difference - if you are not sure, post some 10-15 lines of each here and I should be able to do that. -- Mats -- Mats | |
| matsp is offline | |
| | #11 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,710
| In addition, do programs created with say gcc run as expected? |
| Salem is offline | |
| | #12 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,768
| Hey Kerryhall, what does the output of "ldd ./main" say? Programs on Linux can give a "No such file or directory" when they aren't dynamically linked quite right. Last edited by brewbuck; 09-03-2007 at 11:58 AM. |
| brewbuck is offline | |
| | #13 |
| Registered User Join Date: Sep 2007
Posts: 10
| programs created with gcc work fine. Am I linking right? my assembling and linking commands: Code: nasm -f elf main.asm ld -s -o main main.o /usr/lib/libGL.so /usr/lib/libGLU.so /usr/lib/libSDL.so and here is the result of ldd Code: kerry@BigOwl:~/Programming/x86_asm/extern_func_03$ ldd main /usr/bin/ldd: line 117: ./main: No such file or directory |
| kerryhall is offline | |
| | #14 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,768
| The file's there, it's executable, objdump thinks it's okay, but ldd borks too. Well, ldd works by setting some magic environment variables and then running the binary, so that would be expected. This is just a wild guess, but can you run ANY program called ./main? Try copying /bin/ls to ./main and see if that will run. |
| brewbuck is offline | |
| | #15 |
| Registered User Join Date: Sep 2007
Posts: 10
| Yes, I can run any program called main. |
| kerryhall is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| File Writing Problem | polskash | C Programming | 3 | 02-13-2009 10:47 AM |
| Inventory records | jsbeckton | C Programming | 23 | 06-28-2007 04:14 AM |
| Encryption program | zeiffelz | C Programming | 1 | 06-15-2005 03:39 AM |
| simulate Grep command in Unix using C | laxmi | C Programming | 6 | 05-10-2002 04:10 PM |
| Need a suggestion on a school project.. | Screwz Luse | C Programming | 5 | 11-27-2001 02:58 AM |