title: Error during Cross-compiling C code with Dynamic libraries
body: <p>I've two files:</p>
  <p>lib.c</p>
  <pre><code>#include&lt;stdio.h&gt;
  
  void hi() {
    printf(&quot;Hi i'm a library function in lib.so\n&quot;);
  } 
  </code></pre>
  <p>and main.c</p>
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;dlfcn.h&gt;
  /* based on Jeff Scudder's code */
  int main() {
    void *SharedObjectFile;
    void (*hi)();
  
    // Load the shared libary;
    SharedObjectFile = dlopen(&quot;./lib.so&quot;, RTLD_LAZY);
  
    // Obtain the address of a function in the shared library.
    ciao = dlsym(SharedObjectFile, &quot;hi&quot;);
  
    // Use the dynamically loaded function.
    (*hi)();
  
    dlclose(SharedObjectFile);
  }
  </code></pre>
  <p>And I've tried to build an executables using the following commands:</p>
  <blockquote>
  <p>export LD_LIBRARY_PATH=<code>pwd</code></p>
  <p>gcc -c -fpic lib.c</p>
  <p>gcc -shared -lc -o lib.so lib.o</p>
  <p>gcc main.c -ldl</p>
  </blockquote>
  <p>And it works pretty well.
  Then I've tried to export my program on Android (Nexus One, with ARM-v7-0a arch) using the following commands:</p>
  <blockquote>
  <p>export LD_LIBRARY_PATH=<code>pwd</code></p>
  <p>arm-none-linux-gnueabi-gcc -c -fpic lib.c</p>
  <p>arm-none-linux-gnueabi-gcc -shared -lc -o lib.so lib.o</p>
  <p>arm-none-linux-gnueabi-gcc main.c -ldl -o main</p>
  <p>adb push main /system/app</p>
  </blockquote>
  <p>The result of executing ./main on the correct folder on my smartphone is just:</p>
  <blockquote>
  <p>./main: not found</p>
  </blockquote>
  <p>even if my file is right there!</p>
  <p>Am I missing anything during the cross-compile process? Any help?
  I'm using the cross-compiler from CodeSourcery and it works well for static programs without .so libraries.
  Thanks</p>
  <p><em><strong>EDIT</strong></em>: as Igor states below, that was a linker issue. This command fixes it:</p>
  <blockquote>
  <p>arm-none-linux-gnueabi-gcc -o test main.c -Wl,--dynamic-linker=/system/bin/linker -ldl</p>
  </blockquote>
  <p>in my very case I need other libraries because in /system/lib/ there are no many .so files.</p>