使用独立工具链android arm构建本机库

时间:2011-12-22 15:31:26

标签: android android-ndk cross-compiling toolchain

我正在尝试将libraw构建为Android共享库。看起来lib太复杂了,无法与Android.mk等一起使用,或者更好:我还没有能力做到这一点。

我尝试使用NDK中的独立工具链,但是在编译这个lib时我遇到了困难。

这是我编译lib的路径。请指出我是否犯了明显的错误:

  1. 我下载了ndk。
  2. 跑:make-standalone-toolchain.sh
  3. 在我的bin中添加了该独立工具链的PATH文件夹作为第一项。
  4. 使用./configure启用--host=arm-linux-androideabi。这成功了
  5. make,这里撞得非常快。
  6.     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
    

    我怀疑这个错误消息在stackoverflow中是有用的,但是我想知道我是否应该应用一些额外的标志或配置来使其工作?

    请注意,如果只编译我的系统而没有交叉编译,我就能成功编译这个库。 (linux 32bit)。

    当我查看构建GDAL for Android(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 个答案:

答案 0 :(得分:4)

我必须添加swab函数的实现,因为NDK没有那个。{1}}函数。 之后这个编译好了(但我使用了crystax ndk)。

更好的方法是使用Android.mk文件并使用ndk-build进行编译。

答案 1 :(得分:2)

问题底部出现链接器错误,因为来自NDK r7的make-standalone-toolchain.sh会创建不完整的工具链(它会遗漏某些库,包括libsupc++.a)。我建议你尝试从以前的NDK版本之一制作工具链(r6b应该没问题)。

相关问题