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/ -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

13

1 Answer

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy