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