3

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?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
  • Is there a particular reason you want to use the Berkeley DB specifically? There are other database solutions that are more well-supported for the iOS platform. – Aidan Steele Sep 19 '11 at 22:20
  • I have searched over Google but not found any measure advantage of Berkeley DB within iOS App. Can you please let us know what advantages we can get with this in comparison to traditional SQLITE database ? – Nikh1414 Apr 21 '16 at 09:01

3 Answers3

5

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

Community
  • 1
  • 1
N_A
  • 19,799
  • 4
  • 52
  • 98
1

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.

kalana
  • 89
  • 5
0

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

Chris Suter
  • 2,897
  • 2
  • 19
  • 10