使用独立工具链在Android ARM上构建本地库

5
我正在尝试将libraw构建为Android共享库。看起来使用Android.mk等工具太复杂了,或者更好的方法是:我还没有能力做到这一点。我尝试使用NDK中的独立工具链,但在编译此库时遇到了问题。以下是我编译该库的路径。如果我犯了明显的错误,请指出: 1. 下载了NDK。 2. 运行:make-standalone-toolchain.sh 3. 将该独立工具链的bin文件夹作为第一个项目添加到我的PATH中。 4. 使用--host=arm-linux-androideabi运行./configure。这成功了。 5. 运行make,但很快就崩溃了。
    LibRaw-0.14.4$ make
    depbase=`echo internal/dcraw_common.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
        /bin/bash ./libtool --tag=CXX   --mode=compile arm-linux-androideabi-g++ -DPACKAGE_NAME=\"LibRaw\" -DPACKAGE_TARNAME=\"libraw\" -DPACKAGE_VERSION=\"0.14.4\" -DPACKAGE_STRING=\"LibRaw\ 0.14.4\" -DPACKAGE_BUGREPORT=\"info@libraw.org\" -DPACKAGE_URL=\"http://www.libraw.org\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I.   -I/usr/local/include  -g -O2 -MT internal/dcraw_common.lo -MD -MP -MF $depbase.Tpo -c -o internal/dcraw_common.lo internal/dcraw_common.cpp &&\
        mv -f $depbase.Tpo $depbase.Plo
    libtool: compile:  arm-linux-androideabi-g++ -DPACKAGE_NAME=\"LibRaw\" -DPACKAGE_TARNAME=\"libraw\" -DPACKAGE_VERSION=\"0.14.4\" "-DPACKAGE_STRING=\"LibRaw 0.14.4\"" -DPACKAGE_BUGREPORT=\"info@libraw.org\" -DPACKAGE_URL=\"http://www.libraw.org\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I. -I/usr/local/include -g -O2 -MT internal/dcraw_common.lo -MD -MP -MF internal/.deps/dcraw_common.Tpo -c internal/dcraw_common.cpp  -fPIC -DPIC -o internal/.libs/dcraw_common.o
    internal/dcraw_common.cpp: In member function 'void LibRaw::read_shorts(ushort*, int)':
    internal/dcraw_common.cpp:119: error: 'swab' was not declared in this scope
    internal/dcraw_common.cpp: In member function 'void LibRaw::write_ppm_tiff()':
    internal/dcraw_common.cpp:9235: error: 'swab' was not declared in this scope
    make: *** [internal/dcraw_common.lo] Error 1
编译错误,未声明'swab'。

我怀疑在stackoverflow上这个错误信息并没有什么用,但是我想知道是否应该应用一些附加标志或配置才能使它正常工作?

请注意,如果只编译我的系统(linux 32位),则可以成功编译此库。

当我查看用于构建Android GDAL的指令here时,它使用了一个额外的设置LIBS="-lsupc++ -lstdc++"。这将链接STL和C++异常? 但是,当我在运行我的configure之前设置这些参数时,我立即会遇到像以下这样的错误:

configure:3018: checking whether the C++ compiler works
configure:3040: arm-linux-androideabi-g++    conftest.cpp -lsupc++ -lstdc++ >&5
/tmp/android-chain/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: cannot find -lsupc++
collect2: ld returned 1 exit status

所以,我有点困惑。有人有想法吗?

2个回答

4

我不得不添加一个swab函数的实现,因为NDK没有它。

后来,使用crystax ndk编译成功了。

工具上更好的方法是只需使用一个Android.mk文件,并使用ndk-build进行编译。


嗨@Peterdk,你能告诉我你从哪里得到了swab函数的实现吗?还是你自己写的? - asloob
嗨,我想我只是在谷歌上搜索了它。我没有自己编写它。也许还结合了对Crystax的搜索。 - Peterdk
嗨,请在这里添加一个链接,以便其他用户使用。:) - Peterdk
这是链接 swab.cpp - asloob

2

你提供的问题底部出现了链接错误,这是因为NDK r7中的make-standalone-toolchain.sh创建了不完整的工具链(缺少一些库,包括libsupc++.a)。我建议你尝试从之前的NDK版本(如r6b)中创建一个工具链。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接