小编Nit*_*ito的帖子

Android动态链接库无法解析主程序的符号

我可以成功地在C中创建一个链接到库的程序,并且能够调用该库的函数.如果该库从主程序调用函数,则会出现错误:

root@android:/data/local/tmp # ./helloworld                                    
link_image[1966]:   637 could not load needed library 'libhello.so' for './helloworld' (reloc_library[1315]:   637 cannot locate 'crossfunction'...) CANNOT LINK EXECUTABLE
Run Code Online (Sandbox Code Playgroud)

代码在两个C文件中,我还包括Makefile.hello.c是保存函数hello的库,由main.c(主程序)调用.函数hello尝试调用函数crossfunction并且在android中不起作用(在Linux中它运行得非常好).我怀疑来自android链接器,但到目前为止还没有证据(请参阅https://android.googlesource.com/platform/bionic/+/froyo-release/linker/README.TXT).

另一个好的提示可能是rehellf输出中的NOTYPE赋值,用于libhello.so文件中的交叉函数.请看下面.

         5: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND crossfunction
Run Code Online (Sandbox Code Playgroud)

可能在编译器标志或链接器标志中的任何提示?

::::::::::::::
main.c
::::::::::::::
#include <stdio.h>
extern void hello(const char* name);
int main(void) {
  hello("World!");
}

void crossfunction(void) {
  printf("This is called from the library\n");
}
::::::::::::::
hello.c
::::::::::::::
#include <stdio.h>
extern void crossfunction(void);
static char *s;      
void hello(const char* name) {
  s = "my second …
Run Code Online (Sandbox Code Playgroud)

linker android linker-errors

5
推荐指数
1
解决办法
4860
查看次数

标签 统计

android ×1

linker ×1

linker-errors ×1