I'm trying to build a dynamic library for android wrapper around libcrypto.a as described in
我正在尝试在libcrypto周围为android包装器构建一个动态库。一个描述
http://wiki.openssl.org/index.php/FIPS_Library_and_Android#Using_FIPS_OpenSSL_in_a_real_Application
http://wiki.openssl.org/index.php/FIPS_Library_and_Android Using_FIPS_OpenSSL_in_a_real_Application
I've produced the libcrypto.a as suggested on the page, but when I try to compile my wrapper.c I get a linker error, multiple definition of 'atexit'
我产生了libcrypto。正如页面上建议的,但是当我试图编译包装器时。c我得到一个链接错误,多重定义的" atexit "
Here's the command line I'm using to compile:
下面是我用来编译的命令行:
arm-linux-androideabi-gcc wrapper.c -fPIC -shared -I/usr/local/ssl/android-14/include -Wl,-Bstatic -lcrypto -L/usr/local/ssl/android-14/lib -o libwrapper.so --sysroot=/Users/scoleman/android-ndk-r9d/platforms/android-14/arch-arm -Wl, -Bdynamic
Here are the results:
这里是结果:
/Users/scoleman/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: /Users/scoleman/android-ndk-r9d/platforms/android-14/arch-arm/usr/lib/libc.a(atexit.o): multiple definition of 'atexit'
/Users/scoleman/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /Users/scoleman/android-ndk-r9d/platforms/android-14/arch-arm/usr/lib/crtbegin_so.o: previous definition here
/Users/scoleman/android-ndk-r9d/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ldl
collect2: ld returned 1 exit status
Here's my wrapper.c:
这是我的wrapper.c:
#include <string.h>
#include <jni.h>
int MY_FIPS_mode() {
int mode = mode = FIPS_mode();
return mode;
}
1 个解决方案
#1
3
Here's the command line I'm using to compile:
arm-linux-androideabi-gcc wrapper.c -fPIC -shared -I/usr/local/ssl/android-14/include -Wl,-Bstatic -lcrypto -L/usr/local/ssl/android-14/lib -o libwrapper.so --sysroot=/Users/scoleman/android-ndk-r9d/platforms/android-14/arch-arm -Wl, -Bdynamic
I was able to duplicate the issue with your command line. The way I would approach this is (line breaks added for readability):
我可以用命令行复制这个问题。我的方法是(为了可读性而添加换行符):
arm-linux-androideabi-gcc wrapper.c -fPIC -shared -o libwrapper.so
--sysroot=.../android-ndk-r9d/platforms/android-14/arch-arm
-I/usr/local/ssl/android-14/include
/usr/local/ssl/android-14/lib/libssl.a
/usr/local/ssl/android-14/lib/libcrypto.a
-ldl
--sysroot
will bring in the platform headers and libraries for Android 4.0 (API 14). That should be where atexit
is defined. I think the -Bstatic
and -Bdynamic
might be complicating things since atexit
was provided by both libc.a
and crtbegin_so.o
.
——sysroot将引入Android 4.0 (API 14)的平台标题和库。这应该是atexit的定义。我认为-Bstatic和-Bdynamic可能会使事情复杂化,因为atexit是由libc提供的。一个和crtbegin_so.o。
I avoid -Bstatic
and -Bdynamic
. When I want static linking, I specifically call out the full pathname of the static library, like /usr/local/ssl/android-14/lib/libcrypto.a
. Remember, an archive is a collection of object files (*.o
), so you can use it wherever you can use an object file.
我避免-Bstatic和-Bdynamic。当我想要静态链接时,我特别要调用静态库的完整路径名,比如/usr/local/ssl/android-14/lib/ libcryptoa。请记住,存档是对象文件(*.o)的集合,因此您可以在任何可以使用对象文件的地方使用它。
Using the setenv-android.sh
script from the page and your source, I was not able to duplicate:
使用setenv-android。sh脚本从页面和您的源代码,我无法复制:
$ . ./setenv-android.sh
ANDROID_NDK_ROOT: /opt/android-ndk-r9
ANDROID_EABI: arm-linux-androideabi-4.6
ANDROID_API: android-14
ANDROID_SYSROOT: /opt/android-ndk-r9/platforms/android-14/arch-arm
ANDROID_TOOLCHAIN: /opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin
CROSS_COMPILE: arm-linux-androideabi-
ANDROID_DEV: /opt/android-ndk-r9/platforms/android-14/arch-arm/usr
$ cat wrapper.c
#include <string.h>
#include <jni.h>
#include <openssl/evp.h>
int MY_FIPS_mode() {
int mode = FIPS_mode();
return mode;
}
$ arm-linux-androideabi-gcc wrapper.c -fPIC -shared -o libwrapper.so \
> --sysroot=$ANDROID_SYSROOT \
> -I/usr/local/ssl/android-14/include \
> /usr/local/ssl/android-14/lib/libssl.a \
> /usr/local/ssl/android-14/lib/libcrypto.a \
> -ldl
$ ls
libwrapper.so setenv-android.sh wrapper.c
$ arm-linux-androideabi-readelf -h libwrapper.so
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: ARM
Version: 0x1
Entry point address: 0x0
Start of program headers: 52 (bytes into file)
Start of section headers: 244660 (bytes into file)
Flags: 0x5000000, Version5 EABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 7
Size of section headers: 40 (bytes)
Number of section headers: 34
Section header string table index: 33
$ arm-linux-androideabi-nm -D libwrapper.so | grep MY_FIPS_mode
00009fa4 T MY_FIPS_mode
#1
3
Here's the command line I'm using to compile:
arm-linux-androideabi-gcc wrapper.c -fPIC -shared -I/usr/local/ssl/android-14/include -Wl,-Bstatic -lcrypto -L/usr/local/ssl/android-14/lib -o libwrapper.so --sysroot=/Users/scoleman/android-ndk-r9d/platforms/android-14/arch-arm -Wl, -Bdynamic
I was able to duplicate the issue with your command line. The way I would approach this is (line breaks added for readability):
我可以用命令行复制这个问题。我的方法是(为了可读性而添加换行符):
arm-linux-androideabi-gcc wrapper.c -fPIC -shared -o libwrapper.so
--sysroot=.../android-ndk-r9d/platforms/android-14/arch-arm
-I/usr/local/ssl/android-14/include
/usr/local/ssl/android-14/lib/libssl.a
/usr/local/ssl/android-14/lib/libcrypto.a
-ldl
--sysroot
will bring in the platform headers and libraries for Android 4.0 (API 14). That should be where atexit
is defined. I think the -Bstatic
and -Bdynamic
might be complicating things since atexit
was provided by both libc.a
and crtbegin_so.o
.
——sysroot将引入Android 4.0 (API 14)的平台标题和库。这应该是atexit的定义。我认为-Bstatic和-Bdynamic可能会使事情复杂化,因为atexit是由libc提供的。一个和crtbegin_so.o。
I avoid -Bstatic
and -Bdynamic
. When I want static linking, I specifically call out the full pathname of the static library, like /usr/local/ssl/android-14/lib/libcrypto.a
. Remember, an archive is a collection of object files (*.o
), so you can use it wherever you can use an object file.
我避免-Bstatic和-Bdynamic。当我想要静态链接时,我特别要调用静态库的完整路径名,比如/usr/local/ssl/android-14/lib/ libcryptoa。请记住,存档是对象文件(*.o)的集合,因此您可以在任何可以使用对象文件的地方使用它。
Using the setenv-android.sh
script from the page and your source, I was not able to duplicate:
使用setenv-android。sh脚本从页面和您的源代码,我无法复制:
$ . ./setenv-android.sh
ANDROID_NDK_ROOT: /opt/android-ndk-r9
ANDROID_EABI: arm-linux-androideabi-4.6
ANDROID_API: android-14
ANDROID_SYSROOT: /opt/android-ndk-r9/platforms/android-14/arch-arm
ANDROID_TOOLCHAIN: /opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin
CROSS_COMPILE: arm-linux-androideabi-
ANDROID_DEV: /opt/android-ndk-r9/platforms/android-14/arch-arm/usr
$ cat wrapper.c
#include <string.h>
#include <jni.h>
#include <openssl/evp.h>
int MY_FIPS_mode() {
int mode = FIPS_mode();
return mode;
}
$ arm-linux-androideabi-gcc wrapper.c -fPIC -shared -o libwrapper.so \
> --sysroot=$ANDROID_SYSROOT \
> -I/usr/local/ssl/android-14/include \
> /usr/local/ssl/android-14/lib/libssl.a \
> /usr/local/ssl/android-14/lib/libcrypto.a \
> -ldl
$ ls
libwrapper.so setenv-android.sh wrapper.c
$ arm-linux-androideabi-readelf -h libwrapper.so
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: ARM
Version: 0x1
Entry point address: 0x0
Start of program headers: 52 (bytes into file)
Start of section headers: 244660 (bytes into file)
Flags: 0x5000000, Version5 EABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 7
Size of section headers: 40 (bytes)
Number of section headers: 34
Section header string table index: 33
$ arm-linux-androideabi-nm -D libwrapper.so | grep MY_FIPS_mode
00009fa4 T MY_FIPS_mode