0

I originally wanted to compile SQLCipher statically since it seems like it is easier to link up, but I have been unsuccessful at that. The only place I can find that discusses compiling SQLCipher on OS X is this blog post, but even he was not able to get the static compiling to work.

I was able to get the dynamic compiling working for the SQLCipher and I am able to use the sqlcipher command line program as mentioned in the blog, but now I want to use sqlcipher in a compiled C++ program. I have never dealt directly with dynamic compiling in the command line so I am a bit lost.

It looks like it produces a libtool file libsqlcipher.la so I am wondering how I should import it in C++ #include "libsqlcipher.h"? Looking around at tutorials for libtool they mostly mention how to compile it but I have not found any simple examples of how to link it.

I attempted something like this based on what I saw but I got a couple of errors:

libtool g++ -o test EncryptDatabases.cpp sqlcipher/libsqlcipher.la
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't open file: g++ (No such file or directory)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: EncryptDatabases.cpp is not an object file (not allowed in a library)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: sqlcipher/libsqlcipher.la is not an object file (not allowed in a library)
MCH
  • 2,124
  • 1
  • 19
  • 34
  • do you have g++ installed? – user3159253 Apr 22 '14 at 02:58
  • Yes, I can compile c++ programs just fine with g++. I've tried another command `g++ EncryptDatabases.cpp -ldl -o test`, looks like it follows the include to the correct path of the dynamic library but maybe I am linking the wrong thing. – MCH Apr 22 '14 at 03:04
  • There is no `libsqlcipher.h` only a `libsqlcipher.la` file. But including that doesn't work either. – MCH Apr 22 '14 at 03:07
  • I was able to compile sqlcipher statically. There is only one `.o` file present which is `sqlite3.o` but it says that there are undefined symbols when I compile it together `g++ EncryptDatabases.cpp sqlcipher/sqlite3.o -o test`, maybe it still needs to link some things dynamically? I can use sqlcipher just fine in iPhone but they have an easy to follow guide for that. I'll probably cross post this on the google group SQLCipher Users. – MCH Apr 22 '14 at 03:43

1 Answers1

0

Not an answer yes, but too long for a comment.

As far as I remember first libtool should be explicitly told to compile source file into a "library object":

libtool --mode=compile g++ -c EncryptDatabases.cpp -o EncryptDatabases.lo

then it should link the binary:

libtool --mode=link g++ -o test EncryptDatabases.lo sqlcipher/libsqlcipher.la

See the docs

user3159253
  • 16,836
  • 3
  • 30
  • 56
  • Hmm, maybe there is something different about libtools on mac because I get this: error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `-' in: --mode=compile – MCH Apr 22 '14 at 03:45
  • Yes, I've checked MacOS X folks made their own Lunapark, exactly as Bender suggested. I'd like to ask if it's crucial for you to use `libtool` to make a shared library. – user3159253 Apr 22 '14 at 22:05
  • I managed to get it working with the static compiled version: https://groups.google.com/forum/#!topic/sqlcipher/DgWSklNTN-4 – MCH Apr 23 '14 at 02:59