编译c-ares库及跨平台编译

下载代码:

打开mac终端,执行如下命令

1、$ git clone https://github.com/c-ares/c-ares.git

2、$ cd c-ares

编译本机库(自己电脑是mac端,其他平台的还未尝试):

1、$ ./buildconf

2、$ autoconf configure.ac

3、$ ./configure

4、$ make

5、$ sudo make install

编译出mac平台的库,在”.libs/“目录下

若以上执行执行过程中有报如下错误:

libtoolize not found.

则需要安装libtool,并且链接:

1、$ brew install libtool

2、$ brew link libtool

 

编译ios平台库:

1、$ cmake -DCMAKE_TOOLCHAIN_FILE=../../../toolchain/iOS.cmake -DCMAKE_IOS_DEVELOPER_ROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/ -DCMAKE_IOS_SDK_ROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/ -GXcode .

参考:https://www.cnblogs.com/wengzilin/p/4466708.html

编译安卓平台库:

1、$ export NDK=/tmp/android-ndk-r8b(本机ndk路径)

2、$NDK/build/tools/make-standalone-toolchain.sh \ --platform=android-19 \ --install-dir=/tmp/my-android-toolchain(本地一个路径,可自行指定)

3、$ export PATH=/tmp/my-android-toolchain/arm-linux-androideabi/bin:$PATH (前面部分/tmp/my-android-toolchain是2中指定的路径)

      另,本机执行的结果是执行到某个目录下的压缩文件arm-linux-androideabi.tar.bz2,提示信息中会显示出该文件的目录,将该压缩文件拷贝到2中指定的目录下,解压缩即可,继续后面的配置。
4、$ export SYSROOT=/tmp/my-android-toolchain/arm-linux-androideabi/sysroot (前面部分/tmp/my-android-toolchain是2中指定的路径)

5、$ export CC="arm-linux-androideabi-gcc --sysroot=$SYSROOT"
6、$ export CXX="arm-linux-androideabi-g++ --sysroot=$SYSROOT"

7、$ ./configure --prefix=$(pwd)/build --host=arm-linux --disable-shared CFLAGS="-march=armv7-a" CPPFLAGS="-D__ANDROID_API__=19"

8、若出现如下错误:
/Users/ouasahikage/my-android-toolchain/arm-linux-androideabi/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory
说明是上面的export配置有问题,自己检查是否配置正确。
9、若配置成功(执行configure命令没有报错),执行make报如下错误:
undefined reference to 'stderr'
说明是AndroidAPI版本较低导致的,应该是从17之后就没有stderr,应当在configure的时候指定一下:CPPFLAGS="-D__ANDROID_API__=19"。

参考链接:http://blog.chinaunix.net/uid-20535334-id-4589762.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值