4

I am learning about compiler linker and loader and was trying to understand the working of linker and loader on my ubuntu 12.04 machine

I wrote 2 simple ".c" files as follows

test.c

#include<stdio.h>
int main(int argc, char **argv)
{
  printf("%d",test_fun(10));
}

test2.c

#include<stdio.h>
int test_fun(int a)
{
  return a*10;
}

Then I executed following commands

cc -c test.c

cc -c test2.c

ld test.o test2.o -o a.out -lc --entry main

Now in my current directory a.out file is generated. I can see the file when I type ls but when I try to run the file as

./a.out

I get error

bash: ./a.out: No such file or directory

What am I doing wrong? Please help me?

Danatela
  • 13,581
  • 11
  • 44
  • 70
Null pointer
  • 2,527
  • 5
  • 25
  • 38
  • 3
    Short answer? Try using `gcc -v` to compile something. Long answer, read [this](http://www.linuxquestions.org/questions/linux-software-2/c-programming-how-to-link-with-glibc-using-ld-903088/). – Elliott Frisch Mar 19 '14 at 05:13
  • 4
    @ElliottFrisch, you can make an answer from your comment. Just explain why not use `cc` and `ld`. – Danatela Mar 19 '14 at 05:18

0 Answers0