chenxiao_ji
ROBOTSWEET
2014-07-26 14:34

Linux下将静态库编译成动态库的问题

  • jni
  • 编译链接
  • 动态库
  • 静态库

使用JNI技术时,需要将第三方提供的静态库编译成动态库,在编译过程中遇到问题,使用gcc进行编译链接:
gcc -I/home/jichenxiao/java/jdk1.8.0_11/include -I/home/jichenxiao/java/jdk1.8.0_11/include/linux -fPIC -shared -o libAir.so AirConditioner.c -L. -Wl,--whole-archive -lBLNetwork-linux-64 -Wl,--no-whole-archive -lpthread -lrt -lm
其中/home/jichenxiao/java/jdk1.8.0_11/include和/home/jichenxiao/java/jdk1.8.0_11/include/linux为jni.h和jni_md.h的路径,libAir.so为输出的动态库,AirConditioner.c为要一起编译的c程序,-lBLNetwork-linux-64为要编译成动态库的静态库文件libBLNetwork-linux-64.a。编译时报的错误为:
/usr/bin/ld: ./libBLNetwork-linux-64.a(aes.o): relocation R_X86_64_32S against `.bss' can not be used when making a shared object; recompile with -fPIC
./libBLNetwork-linux-64.a(aes.o): error adding symbols: Bad value
collect2: error: ld returned 1 exit status
我不懂编译原理,请教大家,希望大家能给出解决方案,谢谢!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答

为你推荐