[Interest] Custom SQLite and linking woes

René Hansen renehh at gmail.com
Thu Feb 1 14:18:17 CET 2018


Hi list,


I've run into a bit of a problem with the way, that I'd like to use SQLite
in my application.

I need to load an extension, which is turned off by default in Qt, so I've
made the following change to `qtbase/src/plugins/sqldrivers/sqlite/
sqlite.pro`:

DEFINES -= SQLITE_OMIT_LOAD_EXTENSION
DEFINES += SQLITE_ENABLE_LOAD_EXTENSION

And then recompiled and installed the plugin as advised in
http://doc.qt.io/qt-5/sql-driver.html:

I'm on macOS, so I've been building against the Homebrew version of of
sqlite3 like so:

$ ~/Code/Qt/5.9/clang_64/bin/qmake
"INCLUDEPATH+=/usr/local/Cellar/sqlite/3.21.0/include"
"LIBS+=-L/usr/local/Cellar/sqlite/3.21.0/lib -lsqlite3" sqlite.pro

I `make install` and then try to use the new plugin and then this error
appears:

dyld: Symbol not found: _sqlite3_intarray_bind
  Referenced from:
/System/Library/Frameworks/CoreData.framework/Versions/A/CoreData
  Expected in: /usr/local/Cellar/sqlite/3.21.0/lib/libsqlite3.0.dylib
 in /System/Library/Frameworks/CoreData.framework/Versions/A/CoreData
The program has unexpectedly finished.

Apparently *CoreData* expects *_sqlite3_intarray_bind* to be defined, but
clearly this isn't present. There's a slight difference in the symbols
available from the systems installed version of sqlite3 and the Homebrew
supplied one:

$ diff <(nm -j /usr/lib/libsqlite3.dylib | grep bind) <(nm -j
/usr/local/Cellar
/sqlite/3.21.0/lib/libsqlite3.0.dylib | grep bind)
10a11
> _sqlite3_bind_pointer
18d18
< _sqlite3_intarray_bind

So, from what I've been able to gather searching for answers regarding
*_sqlite3_intarray_bind,* the solution is to just unset *DYLD_LIBRARY_PATH*,
but ... that sort of defeats the purpose of trying to use a custom version
of sqlite. E.g this answer: https://discussions.apple.com/thread/6646506.

Now, unticking the "Add build library search path to DYLD....." in the run
settings, does enable the application to properly load and run but.. again,
with the wrong version of sqlite:

SELECT sqlite_version(); # returns "3.16.1"

As far as I can tell, this is the version that ships with Qt 5.9:

$ grep "3\.16\.1" ~/Code/Qt/5.9/Src/qtbase/src/3rdparty/sqlite/sqlite3.h
#define SQLITE_VERSION        "3.16.1"

So, what to do here...?

The weird thing is, that if I run these queries in with that version;
3.16.1:

select sqlite_compileoption_used('ENABLE_LOAD_EXTENSION');
select sqlite_compileoption_used('OMIT_LOAD_EXTENSION');

I get back the results of *1* and *0*, which would indicate that he
recompiled plugin somehow picked up the compile time change. Trying to run
a `select load_extension(..)` query however throws back the `not authorized
Unable to fetch row` error indicating extension loading is still not
enabled. And in case you're wondering, I am running
`sqlite3_enable_load_extension(db_handle, 1)` before any of this.

I've tested the 3.21.0 binary of sqlite via the command line and it can
execute a `select load_extension(...)`, query just fine.

Any pointers with this, is much appreciated.


Best regards,

René Hansen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180201/cd2689d6/attachment.html>


More information about the Interest mailing list