How to compile sqlite with ICU?
I downloaded sqlite from http://www.sqlite.org/sqlite-autoconf-3070701.tar.g开发者_开发技巧z
How can I compile sqlite with icu ?
1) You can compile it as dynamic extension of SQLite Citing http://www.sqlite.org/cvstrac/fileview?f=sqlite/ext/icu/README.txt
The easiest way to compile and use the ICU extension is to build and use it as a dynamically loadable SQLite extension. To do this using gcc on *nix:
gcc -shared icu.c `icu-config --cppflags --ldflags` -o libSqliteIcu.so
You may need to add "-I" flags so that gcc can find sqlite3ext.h and sqlite3.h. The resulting shared lib, libSqliteIcu.so, may be loaded into sqlite in the same way as any other dynamically loadable extension.
(loading is .load libSqliteIcu.so
in SQLite prompt)
2) You can compile SQLite with ICU enabled. According to http://www.sqlite.org/compile.html
you should define macro SQLITE_ENABLE_ICU
:
Add -DSQLITE_ENABLE_ICU
to the CFLAGS variable or add #define SQLITE_ENABLE_ICU
in some config file.
Okay, there is something here not described in standard documentation. Here is an example of calling configure with ICU enabled:
CFLAGS='-O3 -DSQLITE_ENABLE_ICU' CPPFLAGS=`icu-config --cppflags` LDFLAGS=`icu-config --ldflags` ./configure
You also should have icu-config
program installed (it is from libicu
or libicu-dev
package)
Whether you build the amalgamation with icu enabled or just icu extension depends on what you want to do with icu.
If you need an icu tokenizer (to do fts) you need to build amalgamation, if you just need the icu functions as https://www.sqlite.org/cgi/src/dir?ci=6cb537bdce85e088&name=ext/icu list then icu extension is enough.
When building icu extension I find I can not name it libSqliteIcu.so
as that readme said b/c when I load it I got this error
sqlite> .load ./libSqliteIcu.so
Error: dlsym(0x7fa073e02c60, sqlite3_sqliteicu_init): symbol not found
After asking the question at sqlit mail list I was told that, which I have confirm.
The symbol name is sqlite3_icu_init. When you load module lib<x>.so
the symbol sqlite3_<x>_init
is called. You need to either (a) rename the shared library to the correct name (libicu.so
) or pass the name of the init function (sqlite3_icu_init) to the loader when you load the module, or (b) change the name of the sqlite3_icu_init
function in the icu.c
source so that it matches the name that the module loader is looking for ...
To compile SQLite with ICU enabled, you should define macro SQLITE_ENABLE_ICU
.
Make sure that you have libicu-dev
(on Debian/Ubuntu) installed.
As @osgx wrote, the standard documentation is lacking ICU-specific flags that you also need to set. icu-config
is deprecated and is missing on Ubuntu 20.04 onwards, thus you should use pkg-config
instead:
CFLAGS="-O2 -DSQLITE_ENABLE_ICU `pkg-config --libs --cflags icu-uc icu-io`" ./configure
make
See:
- How To Use ICU - C++ Makefiles
- Compile-time Options of SQLite
精彩评论