title: Dynamic C/C++ lib for Android 2.2: error Symbol not found
body: <p>I have two projects. One of them is Android app with native code, which just loads dynamically library android_lib.so. </p>
  
  <p>Another project is that library (android_lib.so). Code of this library is simple just for learning how things are going. It has only one function. Here is it: </p>
  
  <pre><code>int calculate (int x, int y)
  {
    return (x*x+y*y);
  }
  </code></pre>
  
  <p>In <strong>Makefile</strong> I use cross-platform compilator from Android 2.2 toolchains (/usr/local/android-ndk-r8/toolchains/arm-linux-androideabi4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc):</p>
  
  <pre><code>NDK_DIR=/usr/local/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin
  ANDROID_GCC=$(NDK_DIR)/arm-linux-androideabi-gcc
  NDK_ROOT=/usr/local/android-ndk-r8
  
  CPPFLAGS = $(NDK_ROOT)/platforms/android-8/arch-arm/usr/include
  CFLAGS =-nostdlib
  LDFLAGS = -Wl,-rpath-link=$(NDK_ROOT)/platforms/android-8/arch-arm/usr/lib/ -L$(NDK_ROOT)/platforms/android-8/arch-arm/usr/lib/
  LIBS=-lc
  
  android_lib.so: calculate.o
      $(ANDROID_GCC) $(CFLAGS)  -shared -o android_lib.so calculate.o 
  
  calculate.o: calculate.c
      $(ANDROID_GCC) $(CPPFLAGS) $(CFLAGS) -c -fPIC calculate.c
  clean:
      rm -f *.o *.so 
  </code></pre>
  
  <p>So I type make and get <strong>android_lib.so</strong>.
  In native part of android project (it is mixed Java/C++ Eclipse project) I call dlopen()</p>
  
  <pre><code>dl_handle = dlopen( lib, RTLD_LAZY );
    if (!dl_handle) {
        error = (char *) dlerror();
        if (error != NULL) {
            __android_log_print(ANDROID_LOG_INFO,"nativeCode",error);
            return -1;
        }
        else {
            sprintf(sError,"%s is not found",lib);
            __android_log_print(ANDROID_LOG_INFO,"nativeCode",sError);
            return -2;
        }
    }
  </code></pre>
  
  <p>It succesfully loads android_lib.so. But if I am trying to call function calculate() I get error.</p>
  
  <pre><code>func = (int (*)(int, int)) dlsym( dl_handle, "calculate" );
    error = (char *) dlerror();
    if (error != NULL) {
        __android_log_print(ANDROID_LOG_INFO,"nativeCode",error);
        return -3;
    }
  </code></pre>
  
  <p>Function returns -3 and in LogCat of Eclipse I can see </p>
  
  <pre><code>01-01 07:00:44.624: I/nativeCode(8696): Symbol not found:
  </code></pre>
  
  <p>Please help me to solve this issue. </p>
  
  <p><strong>Update</strong>:</p>
  
  <pre><code>$ cd /usr/local/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin 
  $ sudo ./arm-linux-androideabi-objdump -T /home/chet/workspace/dinLib/android_lib.so
  
  /home/chet/workspace/dinLib/android_lib.so:     file format elf32-littlearm
  
  DYNAMIC SYMBOL TABLE:
  00000234 l    d  .text  00000000 .text
  00000274 g    D  *ABS*  00000000 __exidx_end
  000012e0 g    D  *ABS*  00000000 _bss_end__
  00000234 g    DF .text  00000040 calculate
  000012e0 g    D  *ABS*  00000000 __bss_start__
  00000274 g    D  *ABS*  00000000 __exidx_start
  000012e0 g    D  *ABS*  00000000 __bss_end__
  000012e0 g    D  *ABS*  00000000 __bss_start
  000012e0 g    D  *ABS*  00000000 __end__
  000012e0 g    D  *ABS*  00000000 _edata
  000012e0 g    D  *ABS*  00000000 _end
  000012e0 g    D  .got   00000000 __data_start
  </code></pre>