开发者

How can I use the Berkeley DB within an iOS application?

I would like to use the Berkeley DB within an iOS application, but I'm not sure how to go about this.

How do开发者_如何学编程 you integrate the Berkeley DB within an iOS project? How do you communicate with it via Objective-C?

Are there any tutorials or examples out there that might demonstrate how to do this?


The first thing to note is that the library is C++, not objective-c. This isn't an issue since objective-c can call C++. Also, there isn't much in the way of tutorials, but here is what you will need to do it yourself:

Download

API

Everything you probably need to know to install is here

The specific section on building it on an iOS device is here

C++ Examples

Calling C++ from Objective-C


I'm using XCode Version 4.3.2 (4E2002) with Berkeley db-5.3.15.

I had to use following when building for Simulator because official doc doesn't seems to be updated.

DEV_iOS=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
export SDK_iOS=${DEV_iOS}/SDKs/iPhoneSimulator5.1.sdk
export COMPILER_iOS=${DEV_iOS}/usr/bin
export CC=${COMPILER_iOS}/gcc
export CXX=${COMPILER_iOS}/g++
export LDFLAGS="-arch i686 -pipe -Os -gdwarf-2 -no-cpp-precomp -mthumb -isysroot ${SDK_iOS}"
export CFLAGS=${LDFLAGS}
export CXXFLAGS=${LDFLAGS}
export LD=${COMPILER_iOS}/ld
export CPP=${COMPILER_iOS}/cpp
export AR=${COMPILER_iOS}/ar
export AS=${COMPILER_iOS}/as
export NM=${COMPILER_iOS}/nm
export CXXCPP=${COMPILER_iOS}/cpp
export RANLIB=${COMPILER_iOS}/ranlib

../dist/configure --host=i686-apple-darwin10 --with-cryptography=no --enable-shared=no --enable-sql --prefix=/build_output_dir

make install

and following for the device.

DEV_iOS=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
export SDK_iOS=${DEV_iOS}/SDKs/iPhoneSimulator5.1.sdk
export COMPILER_iOS=${DEV_iOS}/usr/bin
export CC=${COMPILER_iOS}/gcc
export CXX=${COMPILER_iOS}/g++
export LDFLAGS="-arch armv6 -pipe -Os -gdwarf-2 -no-cpp-precomp -mthumb -isysroot ${SDK_iOS}"
export CFLAGS=${LDFLAGS}
export CXXFLAGS=${LDFLAGS}
export LD=${COMPILER_iOS}/ld
export CPP=${COMPILER_iOS}/cpp
export AR=${COMPILER_iOS}/ar
export AS=${COMPILER_iOS}/as
export NM=${COMPILER_iOS}/nm
export CXXCPP=${COMPILER_iOS}/cpp
export RANLIB=${COMPILER_iOS}/ranlib

../dist/configure --host=arm-apple-darwin10 --with-cryptography=no --enable-shared=no  --enable-sql --prefix=/build_output_dir

make install

I used lipo command to check if resulting libraries build for desired architecture.

lipo -info libdb-5.3.a

Specifying "--enable-sql" at config creates the SQL API for you, I'm using same DB wrapper I used to have for SQLite3.


One thing that isn’t mentioned in any of the other answers is that you have to pay Oracle (for version 2+) if you don't want to use their open source license (which requires you to make your source code available).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜