Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile sqlite with ICU?

Tags:

c++

linux

sqlite

I downloaded sqlite from http://www.sqlite.org/sqlite-autoconf-3070701.tar.gz

How can I compile sqlite with icu ?

like image 471
Vivek Goel Avatar asked Jul 05 '11 06:07

Vivek Goel


2 Answers

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)

like image 199
osgx Avatar answered Sep 24 '22 07:09

osgx


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

like image 40
Qiulang 邱朗 Avatar answered Sep 22 '22 07:09

Qiulang 邱朗