iOS编译Libevent库及踩坑例程

参考脚本

https://github.com/OnionBrowser/OnionBrowser/blob/master/build-libevent.sh

生成的库在dependencies路径下。

问题1

COULD NOT VERIFY PACKAGE SIGNATURE...

解决方案:

修改脚本中的 VERIFYGPG=false

问题2

configure: error: cannot run C compiled programs.

If you meant to cross compile, use `--host'.

See `config.log' for more details

解决方案:

去掉模拟器架构,修改ARCHS="armv7 arm64"

问题3

configure: error: openssl is a must but can not be found. You should add the directory containing openssl.pc' to thePKG_CONFIG_PATH' environment variable, or set CFLAGS' andLDFLAGS' directly for openssl, or use `--disable-openssl' to disable support for openssl encryption

解决方案:

脚本中加入--disable-openssl,即修改为

./configure --disable-shared --enable-static --disable-debug-mode --disable-openssl ${EXTRA_CONFIG} \

修改后的完整脚本参考如下


#!/bin/bash

# Builds libevent for all five current iPhone targets: iPhoneSimulator-i386,

# iPhoneSimulator-x86_64, iPhoneOS-armv7, iPhoneOS-armv7s, iPhoneOS-arm64.

#

# Copyright 2012-2016 Mike Tigas <mike AT tig DOT as>

#

# Based on "build-libssl.sh" in OpenSSL-for-iPhone by Felix Schulze,

# forked on 2012-02-24. Original license follows:

# Copyright 2010 Felix Schulze. All rights reserved.

#

# Licensed under the Apache License, Version 2.0 (the "License");

# you may not use this file except in compliance with the License.

# You may obtain a copy of the License at

#

# http://www.apache.org/licenses/LICENSE-2.0

#

# Unless required by applicable law or agreed to in writing, software

# distributed under the License is distributed on an "AS IS" BASIS,

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

# See the License for the specific language governing permissions and

# limitations under the License.

#

###########################################################################

# Choose your libevent version and your currently-installed iOS SDK version:

#

VERSION="2.1.12-stable"

USERSDKVERSION="15.5"

MINIOSVERSION="10.0"

VERIFYGPG=false

export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890

###########################################################################

#

# Don't change anything under this line!

#

###########################################################################

# No need to change this since xcode build will only compile in the

# necessary bits from the libraries we create

#ARCHS="i386 x86_64 armv7 arm64"

ARCHS="armv7 arm64"

DEVELOPER=`xcode-select -print-path`

#DEVELOPER="/Applications/Xcode.app/Contents/Developer"

# for continuous integration

# https://travis-ci.org/mtigas/iOS-OnionBrowser

if [ "$1" == "--noverify" ]; then

VERIFYGPG=false

fi

if [ "$2" == "--travis" ]; then

ARCHS="i386 x86_64"

fi

if [[ ! -z "$TRAVIS" && $TRAVIS ]]; then

# Travis CI highest available version

echo "==================== TRAVIS CI ===================="

SDKVERSION="9.3"

else

SDKVERSION="$USERSDKVERSION"

fi

cd "`dirname \"$0\"`"

REPOROOT=$(pwd)

# Where we'll end up storing things in the end

OUTPUTDIR="${REPOROOT}/dependencies"

mkdir -p ${OUTPUTDIR}/include

mkdir -p ${OUTPUTDIR}/lib

BUILDDIR="${REPOROOT}/build"

# where we will keep our sources and build from.

SRCDIR="${BUILDDIR}/src"

mkdir -p $SRCDIR

# where we will store intermediary builds

INTERDIR="${BUILDDIR}/built"

mkdir -p $INTERDIR

########################################

cd $SRCDIR

# Exit the script if an error happens

set -e

if [ ! -e "${SRCDIR}/libevent-${VERSION}.tar.gz" ]; then

echo "Downloading libevent-${VERSION}.tar.gz"

curl -LO https://github.com/libevent/libevent/releases/download/release-${VERSION}/libevent-${VERSION}.tar.gz

fi

echo "Using libevent-${VERSION}.tar.gz"

# up to you to set up `gpg` and add keys to your keychain

# may have to import from link on http://www.wangafu.net/~nickm/ or http://www.citi.umich.edu/u/provos/

if $VERIFYGPG; then

if [ ! -e "${SRCDIR}/libevent-${VERSION}.tar.gz.asc" ]; then

curl -LO https://github.com/libevent/libevent/releases/download/release-${VERSION}/libevent-${VERSION}.tar.gz.asc

fi

echo "Using libevent-${VERSION}.tar.gz.asc"

if out=$(gpg --status-fd 1 --verify "libevent-${VERSION}.tar.gz.asc" "libevent-${VERSION}.tar.gz" 2>/dev/null) &&

echo "$out" | grep -qs "^\[GNUPG:\] VALIDSIG"; then

echo "$out" | egrep "GOODSIG|VALIDSIG"

echo "Verified GPG signature for source..."

else

echo "$out" >&2

echo "COULD NOT VERIFY PACKAGE SIGNATURE..."

exit 1

fi

fi

tar zxf libevent-${VERSION}.tar.gz -C $SRCDIR

cd "${SRCDIR}/libevent-${VERSION}"

set +e # don't bail out of bash script if ccache doesn't exist

CCACHE=`which ccache`

if [ $? == "0" ]; then

echo "Building with ccache: $CCACHE"

CCACHE="${CCACHE} "

else

echo "Building without ccache"

CCACHE=""

fi

set -e # back to regular "bail out on error" mode

export ORIGINALPATH=$PATH

for ARCH in ${ARCHS}

do

if [ "${ARCH}" == "i386" ] || [ "${ARCH}" == "x86_64" ];

then

PLATFORM="iPhoneSimulator"

EXTRA_CONFIG=""

else

PLATFORM="iPhoneOS"

EXTRA_CONFIG="--host=arm-apple-darwin14"

fi

mkdir -p "${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk"

export PATH="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/:${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/usr/bin/:${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin:${DEVELOPER}/usr/bin:${ORIGINALPATH}"

export CC="${CCACHE}`which gcc` -arch ${ARCH} -miphoneos-version-min=${MINIOSVERSION}"

./configure --disable-shared --enable-static --disable-debug-mode --disable-openssl ${EXTRA_CONFIG} \

--prefix="${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" \

LDFLAGS="$LDFLAGS -L${OUTPUTDIR}/lib" \

CFLAGS="$CFLAGS -Os -I${OUTPUTDIR}/include -isysroot ${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk" \

CPPFLAGS="$CPPFLAGS -I${OUTPUTDIR}/include -isysroot ${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk"

# Build the application and install it to the fake SDK intermediary dir

# we have set up. Make sure to clean up afterward because we will re-use

# this source tree to cross-compile other targets.

make -j$(sysctl hw.ncpu | awk '{print $2}')

make install

make clean

done

########################################

echo "Build library..."

# These are the libs that comprise libevent. `libevent_openssl` and `libevent_pthreads`

# may not be compiled if those dependencies aren't available.

OUTPUT_LIBS="libevent.a libevent_core.a libevent_extra.a libevent_openssl.a libevent_pthreads.a"

for OUTPUT_LIB in ${OUTPUT_LIBS}; do

INPUT_LIBS=""

for ARCH in ${ARCHS}; do

if [ "${ARCH}" == "i386" ] || [ "${ARCH}" == "x86_64" ];

then

PLATFORM="iPhoneSimulator"

else

PLATFORM="iPhoneOS"

fi

INPUT_ARCH_LIB="${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/lib/${OUTPUT_LIB}"

if [ -e $INPUT_ARCH_LIB ]; then

INPUT_LIBS="${INPUT_LIBS} ${INPUT_ARCH_LIB}"

fi

done

# Combine the three architectures into a universal library.

if [ -n "$INPUT_LIBS"  ]; then

lipo -create $INPUT_LIBS \

-output "${OUTPUTDIR}/lib/${OUTPUT_LIB}"

else

echo "$OUTPUT_LIB does not exist, skipping (are the dependencies installed?)"

fi

done

for ARCH in ${ARCHS}; do

if [ "${ARCH}" == "i386" ] || [ "${ARCH}" == "x86_64" ];

then

PLATFORM="iPhoneSimulator"

else

PLATFORM="iPhoneOS"

fi

cp -R ${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/include/* ${OUTPUTDIR}/include/

if [ $? == "0" ]; then

# We only need to copy the headers over once. (So break out of forloop

# once we get first success.)

break

fi

done

####################

echo "Building done."

echo "Cleaning up..."

rm -fr ${INTERDIR}

rm -fr "${SRCDIR}/libevent-${VERSION}"

echo "Done."

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 220,809评论 6 513
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,189评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 167,290评论 0 359
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,399评论 1 294
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,425评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,116评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,710评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,629评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,155评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,261评论 3 339
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,399评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,068评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,758评论 3 332
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,252评论 0 23
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,381评论 1 271
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,747评论 3 375
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,402评论 2 358