How to implement cross-Compilation of protobuf on armv7, armv7s, and i386 in XCODE

Source: Internet
Author: User

After four days of hard work, I finally completed the cross-Compilation of protobuf2.5.0 on xcode. I hope that my colleagues who encountered the same problems will not be confused. Share as follows:


Step 1: deploy protoc.exe

1) sudo su --- enter the Management Mode

// Perform the following operations to switch to the protobuf Folder:

2)./configure

3) make

4) make check

5) make install

In this case, you can view the makefile file under the protobuf folder, and view the local environment represented by-build and the runtime environment of the compiled library represented by-host.

My local-build = x86_64-apple-darwin12.3.0

-Host = x86_64-apple-darwin12.3.0

These two parameters need to be used in subsequent configuration scripts, consistent with the i686-apple-darwin12.3.0 in the footsteps and the arm-apple-darwin12.3.0 suffix "arm-apple-darwin12.3.0)

6) make distclean clean the generated makefile to prepare for cross-compilation and configuration of the new makefile


Step 2: Configure cross-Compilation

1) execute the script ios-build.sh, the script content is as follows:


Configure_for_platform (){

Export PLATFORM = $1

# Export PLATFORM = iPhoneOS

Echo "Platform is $ {PLATFORM }"


If ["$ PLATFORM" = "iPhoneSimulator"]; then

Export ARCHITECTURE = i386

Export ARCH = i686-apple-darwin12.3.0

Fi


If ["$ PLATFORM" = "iPhoneOS"]; then

Export ARCHITECTURE = $2

Export ARCH = arm-apple-darwin12.3.0

Fi


Export ARCH_PREFIX = $ ARCH-

Export SDKVER = "6.1" # the sdk version must be correct

Export DEVROOT =/Applications/Xcode. app/Contents/Developer/Platforms/$ {PLATFORM}. platform/Developer

Export SDKROOT = "$ DEVROOT/SDKs/$ {PLATFORM} $ SDKVER. sdk"

Export PKG_CONFIG_PATH = "$ SDKROOT/usr/lib/pkgconfig: $ DEVROOT/usr/lib/pkgconfig"

Export AS = "$ DEVROOT/usr/bin/"

Export ASCPP = "$ DEVROOT/usr/bin/"

Export AR = "$ DEVROOT/usr/bin/ar"

Export RANLIB = "$ DEVROOT/usr/bin/ranlib"

# Export CPP = "$ DEVROOT/usr/bin/c ++"

# Export CXXCPP = "$ DEVROOT/usr/bin/c ++"

Export CC = "$ DEVROOT/usr/bin/gcc"

Export CXX = "$ DEVROOT/usr/bin/g ++"

Export LD = "$ DEVROOT/usr/bin/ld"

Export STRIP = "$ DEVROOT/usr/bin/strip"

Export LIBRARY_PATH = "$ SDKROOT/usr/lib"


Export CPPFLAGS = ""

# Export CFLAGS = "-arch armv7-fmessage-length = 0-pipe-fpascal-strings-miphoneos-version-min = 4.0-isysroot = $ SDKROOT-I $ SDKROOT/usr/ include-I $ SDKROOT/usr/include/c ++/4.2.1 /"

Export CFLAGS = "-arch $ {ARCHITECTURE}-fmessage-length = 0-pipe-fpascal-strings-miphoneos-version-min = 4.0-isysroot = $ SDKROOT-I $ SDKROOT/ usr/include-I $ SDKROOT/usr/include/c ++/4.2.1 /"

Export CXXFLAGS = "$ CFLAGS"

# Export LDFLAGS = "-isysroot = '$ sdkroot'-L $ SDKROOT/usr/lib/system-L $ SDKROOT/usr/lib /"

Export LDFLAGS = "-arch $ {ARCHITECTURE}-isysroot = '$ sdkroot'-L $ SDKROOT/usr/lib/system-L $ SDKROOT/usr/lib /"


./Configure -- host =$ {ARCH} -- with-protoc = protoc -- enable-static -- disable-shared

}



Mkdir ios-build


# Build for iPhoneSimulator

Configure_for_platform iPhoneSimulator

Make clean

Make

Cp src/. libs/libprotobuf-lite.a for ios-build/libprotobuf-lite-i386.a

# Extract the complete version (i386)

Cp src/. libs/libprotobuf. a ios-build/libprotobuf-i386.a


# Build for iPhone OS armv7

Configure_for_platform iPhoneOS armv7

Make clean

Make

Cp src/. libs/libprotobuf-lite.a for ios-build/libprotobuf-lite-armv7.a

# Extract the complete version (armv7)

Cp src/. libs/libprotobuf. a ios-build/libprotobuf-armv7.a


# Build for iPhone OS armv7s

Configure_for_platform iPhoneOS armv7s

Make clean

Make

Cp src/. libs/libprotobuf-lite.a for ios-build/libprotobuf-lite-armv7s.a

# Extract the complete version (armv7s)

Cp src/. libs/libprotobuf. a ios-build/libprotobuf-armv7s.a


Make clean


# Cerate a fat library containing all achitectures in libprotobuf-lite.a

Xcrun-sdk iphoneos lipo-arch armv7 ios-build/libprotobuf-lite-armv7.a-arch armv7s ios-build/libprotobuf-lite-armv7s.a-arch i386 ios-build/libprotobuf-lite-i386.a-create-output ios-build/libprotobuf-lite.a

# Merge three full versions of libprotobuf.)

Xcrun-sdk iphoneos lipo-arch armv7 ios-build/libprotobuf-armv7.a-arch armv7s ios-build/libprotobuf-armv7s.a-arch i386 ios-build/libprotobuf-i386.a-create-output ios-build/libprotobuf.


2) copy the packaged libprotobuf-lite.a and libprotobuf. a to the Project for compilation, You can compile protobuf in xcode Simulator version and real machine version, complete the cross-compilation.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.