Score:0

Another no such file or directory? But the file exists!

yt flag

i am facing a problem that consumed a lot of my tine. i am trying to link my object file (small program compiled with nasm) with ld linker and using c functions. I searched a lot and i found that the solution to load all c libs is to pass -lc as option to ld which has honestly muted all the warnings and errors and generated my executable. The problem is i get always "No such file or directory" error when i try to run my program.

I searched a lot on internet and i found this useful answer Ask Ubuntu Answer but unfortunately this didnt solve my problem.

some informations here:

> file main

returned:

main: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld64.so.1, not stripped

The program version is 64 bits and the interpreter exists according to "file command.

> ldd main

returned:

linux-vdso.so.1 (0x00007ffdf4bcc000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7a10b23000)
/lib/ld64.so.1 => /lib64/ld-linux-x86-64.so.2 (0x00007f7a10f14000)

According to "ldd" command, there isno missing shared library

N.B: The same program compiled and linked successfully on with nasm and ld on macosx by adding those options

-macosx_version_min 11.0 -L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -lSystem -no_pie

to the the linker ld.

EDIT1: The linked program works without any issue when i remove the -lc for ld and of course the calls of c functions inside my asm file

EDIT2:

readelf -h main

returned:

ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x4005d0
  Start of program headers:          64 (bytes into file)
  Start of section headers:          19096 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         7
  Size of section headers:           64 (bytes)
  Number of section headers:         21
  Section header string table index: 20

Some extra info about the program

Terrance avatar
id flag
What version of Ubuntu are you using?
Mohamed Elleuch avatar
yt flag
i am using Ubuntu 18.04.6 LTS
Terrance avatar
id flag
This sounds more suited for https://stackoverflow.com/ as a programming question and not as much as an Ubuntu issue.
Mohamed Elleuch avatar
yt flag
i didnt get any error or warning when i compile and link may program. the only error that i get is when i try to run the generated file by: ./main and the bash says: bash: ./main: No such file or directory
Terrance avatar
id flag
Did you make it executable by `chmod +x main`?
Mohamed Elleuch avatar
yt flag
yes i tried it without success already the ld in normal cases generates files with x flag active but althout this i tried it.
Mohamed Elleuch avatar
yt flag
also i tried to open the generated program (main) by an HEX editor. and i found that it looks very normal such as any other executable
Mohamed Elleuch avatar
yt flag
thanks for your help @Terrance, but the issue is not frın my code because i am just trying to show "hello world" to STDOUT from assembler by calling printf ( c function ).
hr flag
`interpreter /lib/ld64.so.1` looks suspicious - does this interpreter exist?
Terrance avatar
id flag
Then please [edit](https://askubuntu.com/posts/1388695/edit) your question and add as much details about the issue you are getting, code, everything that you have tried. The more details you give us the better we can help you!
Mohamed Elleuch avatar
yt flag
@steeldriver honestely all i know from my old experiences is "interpreter /lib/ld64.so.3" do you suggest anu solution to try??
hr flag
Nevermind - I see from your ldd output that it resolves to `/lib64/ld-linux-x86-64.so.2`
Mohamed Elleuch avatar
yt flag
@steeldriver actually your doubt about the interpreter was correct. i solved it. it was an interpreter problem. thnx a lot for all who tried to give a solution
Score:2
yt flag

Thanks to this man who shared his experience with others solution here. thanks to him i was able to solve this problem.

To summarize, as @steeldriver though, there was an interpreter problem. the linker is giving to my program [/lib/ld64.so.1] as ELF interpreter but this path doesnt exist at all and i checked it by:

> ls /lib/ld64.so.1
ls: cannot access '/lib/ld64.so.1': No such file or directory

After that, i checked the interpreters path's on my ubuntu installation by:

> ls /lib64/ld-*
/lib64/ld-linux-x86-64.so.2  /lib64/ld-lsb-x86-64.so.2  /lib64/ld-lsb-x86-64.so.3

so the solution is to create a link of one of this interpreters to the inexistant interpreter path by:

sudo ln -s /lib64/ld-linux-x86-64.so.2 /lib/ld64.so.1

Now we re-check the inexistent interpreter one more time to see if its still inexisting or not:

> ls /lib/ld64.so.1
/lib/ld64.so.1

Now this command has returned /lib/ld64.so.1 instead of "inexistant file". so the problem was solved and i could run ./main successfully

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.