简体   繁体   English

Android NDK的编译库

[英]Compile library for Android NDK

I have a library in c/c++. 我在c / c ++中有一个库。 I have used it successfully in a few c++ programs. 我已经在一些C ++程序中成功使用了它。

I want to test if it compiles on Android, and what size it would be etc. 我想测试它是否可以在Android上编译,以及它的大小等等。
Is there any way for me to compile this library to a .so file without having a whole Android Java project? 我有没有办法在没有整个Android Java项目的情况下将此库编译为.so文件? I know nothing about Android development, but have a friend who wants to use my library. 我对Android开发一无所知,但是有一个朋友想使用我的库。 Can I just supply him with a compiled .so file? 我可以给他提供一个已编译的.so文件吗?
Every resource I found says it needs to be compiled out of a JNI folder in an Android Project. 我发现的每个资源都说它需要从Android Project中的JNI文件夹中编译出来。

I discovered that to use the build-ndk script, I don't need a real project. 我发现使用build-ndk脚本不需要真正的项目。 I created a folder project , with nothing in it except another folder jni , and put all my sources in that folder. 我创建了一个文件夹project ,除了另一个文件夹jni之外,什么都没有,然后将所有源文件都放在该文件夹中。 I then created the Android.mk file and ran the script as described in the ndk docs. 然后,我创建了Android.mk文件,并按照ndk文档中的描述运行了脚本。

What you will need to do this is the android Native Development Kit (NDK) http://developer.android.com/sdk/ndk/index.html and a GCC compiler. 您需要做的是android Native Development Kit(NDK) http://developer.android.com/sdk/ndk/index.html和一个GCC编译器。

You can then create a Makefile with the parameters as shown below (thanks ViTo Brothers Apoyan ) and create your shared library. 然后,您可以使用如下所示的参数创建一个Makefile(感谢ViTo Brothers Apoyan )并创建您的共享库。

GCC := C:\Tools\ndk-toolchain\ndk-standalone\bin\arm-linux-androideabi-gcc.exe
GPP := C:\Tools\ndk-toolchain\ndk-standalone\bin\arm-linux-androideabi-g++.exe
AR  := C:\Tools\ndk-toolchain\ndk-standalone\bin\arm-linux-androideabi-ar.exe

OPTIONS  :=\
-fpic \
-ffunction-sections \
-funwind-tables  \
-fstack-protector \
-D__ARM_ARCH_5__ \
-D__ARM_ARCH_5T__ \
-D__ARM_ARCH_5E__ \
-D__ARM_ARCH_5TE__ \
-Wno-psabi \
-march=armv5te \
-mtune=xscale \
-msoft-float \
-mthumb \
-Os \
-fomit-frame-pointer \
-fno-strict-aliasing \
-finline-limit=64 \
-DANDROID \
-Wa, \
-O2 \
-DNDEBUG \
-g \

default: all


all: obj
    $(AR) r mysharedlibrary.so *.o

obj:
    $(GCC) $(OPTIONS) -c *.c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM