I am trying to compile a simplified C source file by "gcc -S" -> "as" -> "ld" on x86_64 platform.
The process finished with no error, but when executed, "No such file or direcotry" error message is shown.
ctest.c
int main()
{
return 0;
}
> gcc -S ctest.c
> as -o ctest.o ctest.s
> ld -o ctest /usr/lib64/crt1.o /usr/lib64/crti.o ctest.o -lc /usr/lib64/crtn.o
> ./ctest
bash: ./ctest: No such file or directory
> uname -a
Linux mkb3 2.6.27.48-0.3-default #1 SMP 2010-09-20 11:03:26 -0400 x86_64 x86_64 x86_64 GNU/Linux
I also tried to add dynamic link as stated in some google results.
> ld -o ctest -dynamic-linker /lib64/ld-linux.so.2 /usr/lib64/crt1.o /usr/lib64/crti.o ctest.o -lc /usr/lib64/crtn.o
But the error remained.
Comments and suggestions are appreciated.
Edit: I made a mistake the /lib64/ld-linux.so.2 doesn't exist in my linux box. I should have used /lib64/ld-2.9.so. Didn't know that ld doesn't report error with a non-existing library file specified.
-dynamic-linker
works for me, but I have a 32-bit system.
Run gcc -v -o ctest ctest.o
and look at the last line of the output. Try to run it as a command. If that works, start to simplify it, throwing out parts until it no longer works. Then throw out some more parts, etc. That's how I arrived to a command that works.
You can also just use gcc -o ctest ctest.o
instead.