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

有些话、适合烂在心里 提交于 2019-12-04 15:42:25
N_A

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!