Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google Protobuf v2.6.0 Build Script for iOS
protobuf
protobuf-2.6.0
protobuf-2.6.1
protobuf-master

Google Protobuf - Mac OS X and iOS Support

The script in this gist will help you buid the Google Protobuf library for use with Mac OS X and iOS. Other methods (such as homebrew or direct compilation) have issues that prevent their use. The libraries built by this script are universal and support all iOS device architectures including the simluator.

Get the Script

The easiest way to use this script is to simply clone the gist onto your machine using the following command:

$ git clone https://gist.github.com/9487468ae3375d0db0cc.git build-protobuf

Performing the Build

The script will automatically download the tarball from Google Code, so all you need to do is run the script. This will build the 2.6.1 version of Protobuf. The script understands a few command-line options too.

$ cd build-protobuf
$ ./build-protobuf.sh

Add --interactive to the above script if you would like the script to stop after each major operation. This makes it easier to inspect the output from the various steps for potential errors.

Add --master if you would prefer to build from the master branch in the Google Protobuf git repo.

Results

Build results are found in a folder called protobuf-{version}, where {version} will be either 2.6.1 or master. This folder contains bin, include and lib folders.

Integration with Xcode

Create a build rule in your Xcode project with the following settings.

Process *Source files with names matching:* `*.proto`
Using *Custom script:*

cd ${INPUT_FILE_DIR}
${SRCROOT}/Google/protobuf/bin/protoc --proto_path=${INPUT_FILE_DIR} ${INPUT_FILE_PATH} --cpp_out=${DERIVED_FILE_DIR}

Output Files
$(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE).pb.cc
$(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE).pb.h

Depending on where you choose to install the protobuf build, you will need to adjust the path to protoc.

FAQ

Can Protobuf be built using libstdc++?

Unfortunately, the protobuf C++ code is not compatible with libstdc++ at the moment. You must use libc++ instead.

Can you provide a similar script for Android?

No

Why am I gettings all the implicit conversion looses integer precision warnings?

Unfortunately, the code generated by protoc is not 64-bit clean. In practice I have not experienced any issues as a result of this. It would be better if the generated code was reworked for better 64-bit support. This may come with the 3.0 version they are working on now.

#!/bin/bash
echo "$(tput setaf 2)"
echo "###################################################################"
echo "# Preparing to build Google Protobuf"
echo "###################################################################"
echo "$(tput sgr0)"
# The version of Protobuf to build. It must match
# one of the values found in the releases section of the github repo.
# It can be set to "master" when building directly from the github repo.
PROTOBUF_VERSION=2.6.1
# Set to "YES" if you would like the build script to
# pause after each major section.
INTERACTIVE=NO
# A "YES" value will build the latest code from GitHub on the master branch.
# A "NO" value will use the 2.6.1 tarball downloaded from googlecode.com.
USE_GIT_MASTER=NO
while [[ $# > 0 ]]
do
key="$1"
case $key in
-i|--interactive)
INTERACTIVE=YES
;;
-m|--master)
USE_GIT_MASTER=YES
PROTOBUF_VERSION=master
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
function conditionalPause {
if [ "${INTERACTIVE}" == "YES" ]
then
while true; do
read -p "Proceed with build? (y/n) " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi
}
# The results will be stored relative to the location
# where you stored this script, **not** relative to
# the location of the protobuf git repo.
PREFIX=`pwd`/protobuf
if [ -d ${PREFIX} ]
then
rm -rf "${PREFIX}"
fi
mkdir -p "${PREFIX}/platform"
PROTOBUF_GIT_URL=https://github.com/google/protobuf.git
PROTOBUF_GIT_DIRNAME=protobuf
PROTOBUF_RELEASE_URL=https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-${PROTOBUF_VERSION}.tar.gz
PROTOBUF_RELEASE_DIRNAME=protobuf-${PROTOBUF_VERSION}
BUILD_MACOSX_X86_64=YES
BUILD_I386_IOSSIM=YES
BUILD_X86_64_IOSSIM=YES
BUILD_IOS_ARMV7=YES
BUILD_IOS_ARMV7S=YES
BUILD_IOS_ARM64=YES
PROTOBUF_SRC_DIR=/tmp/protobuf
# 13.4.0 - Mavericks
# 14.0.0 - Yosemite
# 15.0.0 - El Capitan
DARWIN=darwin14.0.0
XCODEDIR=`xcode-select --print-path`
IOS_SDK_VERSION=`xcrun --sdk iphoneos --show-sdk-version`
MIN_SDK_VERSION=8.3
MACOSX_PLATFORM=${XCODEDIR}/Platforms/MacOSX.platform
MACOSX_SYSROOT=${MACOSX_PLATFORM}/Developer/MacOSX10.9.sdk
IPHONEOS_PLATFORM=`xcrun --sdk iphoneos --show-sdk-platform-path`
IPHONEOS_SYSROOT=`xcrun --sdk iphoneos --show-sdk-path`
IPHONESIMULATOR_PLATFORM=`xcrun --sdk iphonesimulator --show-sdk-platform-path`
IPHONESIMULATOR_SYSROOT=`xcrun --sdk iphonesimulator --show-sdk-path`
# Uncomment if you want to see more information about each invocation
# of clang as the builds proceed.
# CLANG_VERBOSE="--verbose"
CC=clang
CXX=clang
SILENCED_WARNINGS="-Wno-unused-local-typedef -Wno-unused-function"
# NOTE: Google Protobuf does not currently build if you specify 'libstdc++'
# instead of `libc++` here.
STDLIB=libc++
CFLAGS="${CLANG_VERBOSE} ${SILENCED_WARNINGS} -DNDEBUG -g -O0 -pipe -fPIC -fcxx-exceptions"
CXXFLAGS="${CLANG_VERBOSE} ${CFLAGS} -std=c++11 -stdlib=${STDLIB}"
LDFLAGS="-stdlib=${STDLIB}"
LIBS="-lc++ -lc++abi"
echo "PREFIX ..................... ${PREFIX}"
echo "USE_GIT_MASTER ............. ${USE_GIT_MASTER}"
echo "PROTOBUF_GIT_URL ........... ${PROTOBUF_GIT_URL}"
echo "PROTOBUF_GIT_DIRNAME ....... ${PROTOBUF_GIT_DIRNAME}"
echo "PROTOBUF_VERSION ........... ${PROTOBUF_VERSION}"
echo "PROTOBUF_RELEASE_URL ....... ${PROTOBUF_RELEASE_URL}"
echo "PROTOBUF_RELEASE_DIRNAME ... ${PROTOBUF_RELEASE_DIRNAME}"
echo "BUILD_MACOSX_X86_64 ........ ${BUILD_MACOSX_X86_64}"
echo "BUILD_I386_IOSSIM .......... ${BUILD_I386_IOSSIM}"
echo "BUILD_X86_64_IOSSIM ........ ${BUILD_X86_64_IOSSIM}"
echo "BUILD_IOS_ARMV7 ............ ${BUILD_IOS_ARMV7}"
echo "BUILD_IOS_ARMV7S ........... ${BUILD_IOS_ARMV7S}"
echo "BUILD_IOS_ARM64 ............ ${BUILD_IOS_ARM64}"
echo "PROTOBUF_SRC_DIR ........... ${PROTOBUF_SRC_DIR}"
echo "DARWIN ..................... ${DARWIN}"
echo "XCODEDIR ................... ${XCODEDIR}"
echo "IOS_SDK_VERSION ............ ${IOS_SDK_VERSION}"
echo "MIN_SDK_VERSION ............ ${MIN_SDK_VERSION}"
echo "MACOSX_PLATFORM ............ ${MACOSX_PLATFORM}"
echo "MACOSX_SYSROOT ............. ${MACOSX_SYSROOT}"
echo "IPHONEOS_PLATFORM .......... ${IPHONEOS_PLATFORM}"
echo "IPHONEOS_SYSROOT ........... ${IPHONEOS_SYSROOT}"
echo "IPHONESIMULATOR_PLATFORM ... ${IPHONESIMULATOR_PLATFORM}"
echo "IPHONESIMULATOR_SYSROOT .... ${IPHONESIMULATOR_SYSROOT}"
echo "CC ......................... ${CC}"
echo "CFLAGS ..................... ${CFLAGS}"
echo "CXX ........................ ${CXX}"
echo "CXXFLAGS ................... ${CXXFLAGS}"
echo "LDFLAGS .................... ${LDFLAGS}"
echo "LIBS ....................... ${LIBS}"
conditionalPause
echo "$(tput setaf 2)"
echo "###################################################################"
echo "# Fetch Google Protobuf"
echo "###################################################################"
echo "$(tput sgr0)"
(
if [ -d ${PROTOBUF_SRC_DIR} ]
then
rm -rf ${PROTOBUF_SRC_DIR}
fi
cd `dirname ${PROTOBUF_SRC_DIR}`
if [ "${USE_GIT_MASTER}" == "YES" ]
then
git clone ${PROTOBUF_GIT_URL}
else
if [ -d ${PROTOBUF_RELEASE_DIRNAME} ]
then
rm -rf "${PROTOBUF_RELEASE_DIRNAME}"
fi
curl --location ${PROTOBUF_RELEASE_URL} --output ${PROTOBUF_RELEASE_DIRNAME}.tar.gz
tar xvf ${PROTOBUF_RELEASE_DIRNAME}.tar.gz
mv "${PROTOBUF_RELEASE_DIRNAME}" "${PROTOBUF_SRC_DIR}"
rm ${PROTOBUF_RELEASE_DIRNAME}.tar.gz
# Remove the version of Google Test included with the release.
# We will replace it with version 1.7.0 in a later step.
if [ -d "${PROTOBUF_SRC_DIR}/gtest" ]
then
rm -r "${PROTOBUF_SRC_DIR}/gtest"
fi
fi
)
conditionalPause
if [ "${PROTOBUF_VERSION}" == "master" ]
then
echo "$(tput setaf 2)"
echo "###################################################################"
echo "# Run autogen.sh to prepare for build."
echo "###################################################################"
echo "$(tput sgr0)"
(
cd ${PROTOBUF_SRC_DIR}
( exec ./autogen.sh )
)
else
echo "$(tput setaf 2)"
echo "###################################################################"
echo "# Fetch Google Test & Prepare the Configure Script"
echo "# (note: This section is lifted from autogen.sh)"
echo "###################################################################"
echo "$(tput sgr0)"
(
cd ${PROTOBUF_SRC_DIR}
# Check that we are being run from the right directory.
if test ! -f src/google/protobuf/stubs/common.h
then
cat >&2 << __EOF__
Could not find source code. Make sure you are running this script from the
root of the distribution tree.
__EOF__
exit 1
fi
# Check that gtest is present. Older versions of protobuf were stored in SVN
# and the gtest directory was setup as an SVN external. Now, protobuf is
# stored in GitHub and the gtest directory is not included. The commands
# below will grab the latest version of gtest. Currently that is 1.7.0.
if test ! -e gtest
then
echo "Google Test not present. Fetching gtest-1.7.0 from the web..."
curl --location https://github.com/google/googletest/archive/release-1.7.0.tar.gz --output gtest-1.7.0.tar.gz
tar xvf gtest-1.7.0.tar.gz
rm gtest-1.7.0.tar.gz
mv googletest-release-1.7.0 gtest
fi
autoreconf -f -i -Wall,no-obsolete
rm -rf autom4te.cache config.h.in~
)
fi
conditionalPause
###################################################################
# This section contains the build commands to create the native
# protobuf library for Mac OS X. This is done first so we have
# a copy of the protoc compiler. It will be used in all of the
# susequent iOS builds.
###################################################################
echo "$(tput setaf 2)"
echo "###################################################################"
echo "# x86_64 for Mac OS X"
echo "###################################################################"
echo "$(tput sgr0)"
if [ "${BUILD_MACOSX_X86_64}" == "YES" ]
then
(
cd ${PROTOBUF_SRC_DIR}
make distclean
./configure --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/x86_64-mac "CC=${CC}" "CFLAGS=${CFLAGS} -arch x86_64" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch x86_64" "LDFLAGS=${LDFLAGS}" "LIBS=${LIBS}"
make
make check
make install
)
fi
PROTOC=${PREFIX}/platform/x86_64-mac/bin/protoc
conditionalPause
###################################################################
# This section contains the build commands for each of the
# architectures that will be included in the universal binaries.
###################################################################
echo "$(tput setaf 2)"
echo "###########################"
echo "# i386 for iPhone Simulator"
echo "###########################"
echo "$(tput sgr0)"
if [ "${BUILD_I386_IOSSIM}" == "YES" ]
then
(
cd ${PROTOBUF_SRC_DIR}
make distclean
./configure --build=x86_64-apple-${DARWIN} --host=i386-apple-${DARWIN} --with-protoc=${PROTOC} --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/i386-sim "CC=${CC}" "CFLAGS=${CFLAGS} -mios-simulator-version-min=${MIN_SDK_VERSION} -arch i386 -isysroot ${IPHONESIMULATOR_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -mios-simulator-version-min=${MIN_SDK_VERSION} -arch i386 -isysroot ${IPHONESIMULATOR_SYSROOT}" LDFLAGS="-arch i386 -mios-simulator-version-min=${MIN_SDK_VERSION} ${LDFLAGS} -L${IPHONESIMULATOR_SYSROOT}/usr/lib/ -L${IPHONESIMULATOR_SYSROOT}/usr/lib/system" "LIBS=${LIBS}"
make
make install
)
fi
conditionalPause
echo "$(tput setaf 2)"
echo "#############################"
echo "# x86_64 for iPhone Simulator"
echo "#############################"
echo "$(tput sgr0)"
if [ "${BUILD_X86_64_IOSSIM}" == "YES" ]
then
(
cd ${PROTOBUF_SRC_DIR}
make distclean
./configure --build=x86_64-apple-${DARWIN} --host=x86_64-apple-${DARWIN} --with-protoc=${PROTOC} --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/x86_64-sim "CC=${CC}" "CFLAGS=${CFLAGS} -mios-simulator-version-min=${MIN_SDK_VERSION} -arch x86_64 -isysroot ${IPHONESIMULATOR_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -mios-simulator-version-min=${MIN_SDK_VERSION} -arch x86_64 -isysroot ${IPHONESIMULATOR_SYSROOT}" LDFLAGS="-arch x86_64 -mios-simulator-version-min=${MIN_SDK_VERSION} ${LDFLAGS} -L${IPHONESIMULATOR_SYSROOT}/usr/lib/ -L${IPHONESIMULATOR_SYSROOT}/usr/lib/system" "LIBS=${LIBS}"
make
make install
)
fi
conditionalPause
echo "$(tput setaf 2)"
echo "##################"
echo "# armv7 for iPhone"
echo "##################"
echo "$(tput sgr0)"
if [ "${BUILD_IOS_ARMV7}" == "YES" ]
then
(
cd ${PROTOBUF_SRC_DIR}
make distclean
./configure --build=x86_64-apple-${DARWIN} --host=armv7-apple-${DARWIN} --with-protoc=${PROTOC} --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/armv7-ios "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch armv7 -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch armv7 -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch armv7 -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
make
make install
)
fi
conditionalPause
echo "$(tput setaf 2)"
echo "###################"
echo "# armv7s for iPhone"
echo "###################"
echo "$(tput sgr0)"
if [ "${BUILD_IOS_ARMV7S}" == "YES" ]
then
(
cd ${PROTOBUF_SRC_DIR}
make distclean
./configure --build=x86_64-apple-${DARWIN} --host=armv7s-apple-${DARWIN} --with-protoc=${PROTOC} --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/armv7s-ios "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch armv7s -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch armv7s -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch armv7s -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
make
make install
)
fi
conditionalPause
echo "$(tput setaf 2)"
echo "##################"
echo "# arm64 for iPhone"
echo "##################"
echo "$(tput sgr0)"
if [ "${BUILD_IOS_ARM64}" == "YES" ]
then
(
cd ${PROTOBUF_SRC_DIR}
make distclean
./configure --build=x86_64-apple-${DARWIN} --host=arm --with-protoc=${PROTOC} --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/arm64-ios "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch arm64 -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch arm64 -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch arm64 -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
make
make install
)
fi
conditionalPause
echo "$(tput setaf 2)"
echo "###################################################################"
echo "# Create Universal Libraries and Finalize the packaging"
echo "###################################################################"
echo "$(tput sgr0)"
(
cd ${PREFIX}/platform
mkdir universal
lipo x86_64-sim/lib/libprotobuf.a i386-sim/lib/libprotobuf.a arm64-ios/lib/libprotobuf.a armv7s-ios/lib/libprotobuf.a armv7-ios/lib/libprotobuf.a -create -output universal/libprotobuf.a
lipo x86_64-sim/lib/libprotobuf-lite.a i386-sim/lib/libprotobuf-lite.a arm64-ios/lib/libprotobuf-lite.a armv7s-ios/lib/libprotobuf-lite.a armv7-ios/lib/libprotobuf-lite.a -create -output universal/libprotobuf-lite.a
)
(
cd ${PREFIX}
mkdir bin
mkdir lib
cp -r platform/x86_64-mac/bin/protoc bin
cp -r platform/x86_64-mac/lib/* lib
cp -r platform/universal/* lib
rm -rf platform
lipo -info lib/libprotobuf.a
lipo -info lib/libprotobuf-lite.a
)
if [ "${USE_GIT_MASTER}" == "YES" ]
then
if [ -d "${PREFIX}-master" ]
then
rm -rf "${PREFIX}-master"
fi
mv "${PREFIX}" "${PREFIX}-master"
else
if [ -d "${PREFIX}-${PROTOBUF_VERSION}" ]
then
rm -rf "${PREFIX}-${PROTOBUF_VERSION}"
fi
mv "${PREFIX}" "${PREFIX}-${PROTOBUF_VERSION}"
fi
echo Done!
@ItalyPaleAle

This comment has been minimized.

Copy link

@ItalyPaleAle ItalyPaleAle commented Oct 8, 2014

The README file contains a mistake: it's not ./build-protobuf-2.6.0.sh but ./build-protobuf.sh
That aside, thank you a lot for the script!

@roberthartman

This comment has been minimized.

Copy link

@roberthartman roberthartman commented Nov 1, 2014

Thank you Bennett Smith!

@matthocker

This comment has been minimized.

Copy link

@matthocker matthocker commented Nov 10, 2014

Hi, thanks so much for this. I am having some issues however with the custom script. I needed to change it to:

"${SRCROOT}"/protobuf-2.6.0/bin/protoc --proto_path="${INPUT_FILE_DIR}" "${INPUT_FILE_PATH}" --cpp_out="${DERIVED_FILE_DIR}"

Note the double-quotes; I have spaces in my path names. That allows it to run but then I get an error in the build:

plugin.proto
Shell Script Invocation Error: "FileDescriptorProto" is not defined.

If I run this from the console, I don't get the same issue. Any thoughts?

@matthocker

This comment has been minimized.

Copy link

@matthocker matthocker commented Nov 10, 2014

Another issue... once I "protoc" my .proto files and compile them for ARM64, I get tons of these sorts of warnings and eventually the build fails:

Code:
// To save space, index() is computed by looking at the descriptor's position
// in the parent's array of children.
inline int FieldDescriptor::index() const {
if (!is_extension_) {
return this - containing_type_->fields_;
}

Error from log:
warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
return this - containing_type_->fields_;
~~~~~~ ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

It looks to me like this is failing because of word length issues. Is there a "protoc" setting that I'm not using correctly?

@chenleijava

This comment has been minimized.

Copy link

@chenleijava chenleijava commented Feb 11, 2015

cool ,thanks very much!!!

@wanyancan

This comment has been minimized.

Copy link

@wanyancan wanyancan commented Apr 6, 2015

It works without any problem.

@zagannath

This comment has been minimized.

Copy link

@zagannath zagannath commented Aug 20, 2015

Thanks @BennettSmith can you please add script for Android.

@gagoongx2

This comment has been minimized.

Copy link

@gagoongx2 gagoongx2 commented Sep 21, 2015

Is it possible to build with libstdc++ not libc++ ?

@Gubarev

This comment has been minimized.

Copy link

@Gubarev Gubarev commented Sep 21, 2015

Hi Bennett,

Thanks for so useful script!

There are some issues with building for iOS simulator using XCode 7. Here is discussion: https://forums.developer.apple.com/thread/13795

In Xcode 7, the linker enforces that all files linked together were built for the same platform. You control the platform via -mmacosx-version-min=XX or -miphoneos-version-min=XX compiler options.
You can see which platform an object file was built for by running “otool -lv” on the .a (or .o) file. and look for LC_VERSION. You should see LC_VERSION_MIN_IPHONEOS, LC_VERSION_MIN_MACOSX, LC_VERSION_MIN_WATCHOS, or LC_VERSION_MIN_TVOS.

Thus your script require some updates to be more pedantic and compatible with new XCode 7.
I already forked you gist and made required changes: https://gist.github.com/Gubarev/a5a56135c9ff814b0117

Summary of my changes:

  1. Use "mios-simulator-version-min" instead of "miphoneos-version-min" for simulators. Seems like not too important, but i believe this is more pedantic approach.
  2. Specify min iOS version in CXXFLAGS. Very important when target is iOS simulator, because when this option is missed the compiler assume OS X and put this information in object files. As result it cause linker error. In case when mobile device is target this modification less important, but I updated flags for devices too to keep consistency.
  3. Specify paths to libraries based on IPHONESIMULATOR_SYSROOT in case of simulator target. Very important, because by default linker uses libraries for OS X.
@BennettSmith

This comment has been minimized.

Copy link
Owner Author

@BennettSmith BennettSmith commented Sep 21, 2015

Thanks for the detailed notes Gubarev. I am in the process of updating the script today for Xcode 7, having just run into similar issues this morning. I will pull your changes into the script.

Cheers

-- Bennett

@BennettSmith

This comment has been minimized.

Copy link
Owner Author

@BennettSmith BennettSmith commented Sep 21, 2015

The script has bee updated to include changes from @Gubarev. I have also added support for building from the master branch of the Google Protobuf repo. This means you can now either build for 2.6.1 or the latest 3.x alpha. Both versions are maintained in separate folders relative to the script so you can give them both a try.

@robmaceachern

This comment has been minimized.

Copy link

@robmaceachern robmaceachern commented Sep 24, 2015

Thanks for the script. I'm seeing some linker warnings with Xcode 7.0:

ld: warning: object file (libprotobuf-lite.a(atomicops_internals_x86_gcc.o)) was built for newer iOS version (9.0) than being linked (8.0)

I've specified MIN_SDK_VERSION=8.0 in the script prior to building. Is there anything else I can do to make Xcode 7 happy?

@gagoongx2

This comment has been minimized.

Copy link

@gagoongx2 gagoongx2 commented Sep 30, 2015

Thanks @BennettSmith

linke error in Xcode 7
(linker command failed with exit code 1)

Solution is below
not include mac x86_64 library in universal
remove - cp -r platform/x86_64-mac/lib/* lib

Plus
If you want to build with libstdc++.
change compiler clang to gcc , g++

CC=gcc
CXX=g++
STDLIB=libstdc++

@ksc91u

This comment has been minimized.

Copy link

@ksc91u ksc91u commented Oct 9, 2015

https://gist.github.com/ksc91u/bef7e2482018a5d363b8

  • modified version to add -fembed-bitcode for iOS 9
  • change lipo command, do not require all platforms to be built.
@stoeckley

This comment has been minimized.

Copy link

@stoeckley stoeckley commented Dec 20, 2015

Using Xcode 7, I'm getting errors as reported by others, even with the latest version of this script:

building for iOS simulator, but linking in object file built for OSX, for architecture x86_64

I will try one of the forks out there.

@stoeckley

This comment has been minimized.

Copy link

@stoeckley stoeckley commented Dec 20, 2015

There must be still some important differences between this script and the fork of it here:

https://gist.github.com/Gubarev/a5a56135c9ff814b0117

I was able to build and compile fine for iOS in Xcode 7 by linking to the library built with the fork, but not the one built with the script here.

@mtngld

This comment has been minimized.

Copy link

@mtngld mtngld commented Jan 10, 2016

Hi, I'm running the build script and getting this error when trying to create the universal lib:

###################################################################
# Create Universal Libraries and Finalize the packaging
###################################################################

fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: x86_64-sim/lib/libprotobuf.a and i386-sim/lib/libprotobuf.a have the same architectures (x86_64) and can't be in the same fat output file
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: x86_64-sim/lib/libprotobuf-lite.a and i386-sim/lib/libprotobuf-lite.a have the same architectures (x86_64) and can't be in the same fat output file

Not sure why the x86_64 and the i386 libs have the same architecture, what am I missing?�

Thanks

@robmaceachern

This comment has been minimized.

Copy link

@robmaceachern robmaceachern commented Mar 1, 2016

I made one change to the script that seemed to resolve all my object file was built for newer iOS version linker warnings. You can check it out here: https://gist.github.com/robmaceachern/624633ff957cf147bfcd/revisions#diff-146617bd233bdd2215d983c3b57d62f2L329

@benstadin

This comment has been minimized.

Copy link

@benstadin benstadin commented Nov 10, 2016

I'm getting errors with lipo:

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

Create Universal Libraries and Finalize the packaging

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

fatal error: lipo: can't open input file: x86_64-sim/lib/libprotobuf.a (No such file or directory)
fatal error: lipo: can't open input file: x86_64-sim/lib/libprotobuf-lite.a (No such file or directory)
cp: platform/universal/*: No such file or directory
input file lib/libprotobuf.a is not a fat file
Non-fat file: lib/libprotobuf.a is architecture: x86_64
input file lib/libprotobuf-lite.a is not a fat file
Non-fat file: lib/libprotobuf-lite.a is architecture: x86_64
Done!

@nitinh

This comment has been minimized.

Copy link

@nitinh nitinh commented Dec 5, 2016

I am getting following error while running script compile_ios_protobuf.sh to make tensoflow for ios on a MacBook Pro,
Static Libraries for ios_arm64 ,ios_arm7,ios_arm7s,iossim_386 are getting compiled but iossim_x86_64 can't be built due to following error

===========================

checking whether we are cross compiling... configure: error: in ~/Tensorflow_on_ios/tensorflow-master/tensorflow/contrib/makefile/downloads/protobuf': configure: error: cannot run C compiled programs. If you meant to cross compile, use --host'.
See `config.log' for more details

  • make
    make: *** No targets specified and no makefile found. Stop.
  • make install
    make: *** No rule to make target `install'. Stop.
  • make distclean
    make: *** No rule to make target `distclean'. Stop.
@carloscabanero

This comment has been minimized.

Copy link

@carloscabanero carloscabanero commented Dec 6, 2016

@nitinh @benstadin That is a problem with Sierra due to the compiler :( . Found a fix thanks to tensorflow/tensorflow#4640. Just remove the --build=x86_64-xxxx part from the x86_64 simulator. Or compile on < Sierra.

@sureshjoshi

This comment has been minimized.

Copy link

@sureshjoshi sureshjoshi commented Nov 9, 2017

Just as a recommendation for anyone looking into building protobuf 3's, Google maintains TensorFlow, which has an iOS lib - and it uses Protobuf under the hood. So, if you build TensorFlow for iOS, you'll get the protobuf libraries for iOS....

Alternatively, this file should compile only the protobufs. https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/makefile/compile_ios_protobuf.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment