How to Compile SQLite with Icu

How to 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)

How to use sqlite icu in like query

According to the full text search documentation you should use tokenize=icu en_US for example (specify an ICU locale identifier).

Also, you should have ICU loaded.

Compiling the icu sqlite extension statically linked to icu

This command line worked for me on Linux:

g++ -shared --language c  -o libSqliteIcu.so icu.c  -I../icu/source/common -I../icu/source/i18n -lpthread -lm   -L../icu/source/lib -lsicui18n -lsicuuc -lsicudata  -lpthread -lm 

Notice the ordering of the library files, and the use of g++ to make sure the c++ runtime is referenced even though we're compiling a C file.

NB.
I used the output of icu-config --prefix=../icu/source --ldflags.

undefined symbol uregex_setText_64 sqlite icu extension

Problem solved.

Solution:

gcc --shared -fPIC -O3 -o libSqliteIcu.so ../src/ext/icu/icu.c -licui18n -licuuc -licudata -L/usr/local/lib

Details:

pkg-config --libs icu-i18n

returns:

-licui18n -licuuc -licudata -L/usr/local/lib


Related Topics



Leave a reply



Submit