title: Why symbols of a shared library are not resolved at link time?
body: <p>This is my 2nd post on this site in my effort to understand the compilation/linking process with gcc. When I try to make an executable, symbols need to be resolved at link time, but when I try to make a shared library, symbols are not resolved at link time of this library. They will perhaps be resolved when I am trying to make an executable using this shared library. Hands-on:</p>
  
  <pre><code>bash$ cat printhello.c
  #include &lt;stdio.h&gt;
  //#include "look.h"
  
  void PrintHello()
  {
  look();
  printf("Hello World\n");
  }
  
  bash$ cat printbye.c
  #include &lt;stdio.h&gt;
  //#include "look.h"
  
  void PrintBye()
  {
  look();
  printf("Bye bye\n");
  }
  
  bash$  cat look.h
  void look();
  
  bash$ cat look.c
  #include &lt;stdio.h&gt;
  
  void look()
  {
  printf("Looking\n");
  }
  
  bash$ gcc printhello.c printbye.c
  /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o: In function `_start':
  (.text+0x18): undefined reference to `main'
  /tmp/cck21S0u.o: In function `PrintHello':
  printhello.c:(.text+0x7): undefined reference to `look'
  /tmp/ccNWbCnd.o: In function `PrintBye':
  printbye.c:(.text+0x7): undefined reference to `look'
  collect2: ld returned 1 exit status
  
  bash$ gcc -Wall -shared -o libgreet printhello.c printbye.c
  printhello.c: In function 'PrintHello':
  printhello.c:6: warning: implicit declaration of function 'look'
  printbye.c: In function 'PrintBye':
  printbye.c:5: warning: implicit declaration of function 'look'
  </code></pre>
  
  <p>So my question is why are symbols not resolved when I am linking a shared library. This work(Resolving symbols of its downstream) will need to be done when I will use this library to make an executable, but that means we need to know what this library depends on when using this library, but isn't it not undesirable?</p>
  
  <p>Thanks,
  Jagrati</p>