Compile SQLCipher as a .dylib for OS X to include in project

Hi,

I’m trying to use SQLCipher with Couchbase Lite and I’d like to compile it as a dynamic library. Unfortunately all my attempts have been futile with varying types of errors after I compile.

I tried using the Xcode project that comes with SQLCipher and changing the library type from Static to dynamic, but that didn’t seem to work. Although I could build the library, it didn’t work when I tried to use it. It was unable to open any of my encrypted database files.

I also tried using the command-line with the following config:

./configure --enable-load-extension --enable-tempstore=yes --with-crypto-lib=commoncrypto CFLAGS="-DSQLITE_HAS_CODEC -mmacosx-version-min=10.10 -arch x86_64 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4_UNICODE61" LDFLAGS="/System/Library/Frameworks/Security.framework/Versions/Current/Security"

make

But I didn’t see where the .dylib file was generated other than inside a hidden .libs folder. I took the libsqlcipher.0.dylib file from within there and tried to link it to my app, but upon launch I just got an “image not found” error: dyld: Library not loaded: /usr/local/lib/libsqlcipher.0.dylib

Any suggestions for what to try are welcome.

I posted this same message on the SQLCipher Google groups, but forgot that this is where we discuss SQLCipher now. So sorry for the double post.

Thanks,

Brendan

Hi @BrendanD , Using the command line build, have you tried to run “make install”, and then use the libraries from their final location?

Hi Steven,

I didn’t because I didn’t want to install them in my system. What’s the parameter to have them installed in a specific directory?

Thanks,

Brendan

Hi @sjlombardo,

Ok, I used the --prefix command to install into a custom folder. But do I use the dylib file or the .a file or all of them?

This is what got created:

libsqlcipher.0.dylib
libsqlcipher.a
libsqlcipher.dylib
libsqlcipher.la
pkgconfig

libsqlcipher.dylib is an alias that points to libsqlcipher.0.dylib

I’m assuming the .a is just the static build of the library.

Do I just drag the libsqlcipher.0.dylib file in my Xcode 7 project? What about the header files in the includes folder? Do I also need to add those to my project?

Thanks,

Brendan

Hello @BrendanD

Glad to hear you worked it out with --prefix.

If you want to use the shared library, you would definitely need to use the .dylib file, the .a is the static library. I’m not familiar with Couchbase Lite or how its built, but in general you should be able to reference the dylib from your XCode project (e.g. add it to the link build phase of the target).

You would still need to ensure that the headers can be located via the includes folder in order to make use of the library. In practice this would at least mean that the target’s headers search path includes the include directory. Remember you’ll also still need to set the defines in the target for SQLITE_HAS_CODEC, etc., to get visibility of the key functions.

@BrendanD It sounds like your build is working, but perhaps your application can’t find the dylib when it’s being run. The dylib would need to be loaded at runtime. If the system can’t find the file, it could cause a crash. You’ll need to ensure the dylib is copied to the app output directory, or that the path to the dylib is in DYLD_LIBRARY_PATH for it to be resolved.