Note that there are some explanatory texts on larger screens.

plurals
  1. POError during Cross-compiling C code with Dynamic libraries
    primarykey
    data
    text
    <p>I've two files:</p> <p>lib.c</p> <pre><code>#include&lt;stdio.h&gt; void hi() { printf("Hi i'm a library function in lib.so\n"); } </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("./lib.so", RTLD_LAZY); // Obtain the address of a function in the shared library. ciao = dlsym(SharedObjectFile, "hi"); // 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</em></strong>: 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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload