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
Statically Linking System Libraries, Libc, Pthreads, to Aid in Debugging
Hello World Python Extension in C++ Using Boost
Returning Temporary Object and Binding to Const Reference
Change the Current Working Directory in C++
Math-Like Chaining of the Comparison Operator - as In, "If ( (5<J<=1) )"
When Is It Best to Use the Stack Instead of the Heap and Vice Versa
How to Statically Link Standard Library to My C++ Program
Why Are Rvalues References Variables Not Rvalue
What Does the "Lock" Instruction Mean in X86 Assembly
Why Isn't Malloc Filling Up Memory
Send Mail Using Smtp in C++ on Linux
Using a Stl Map of Function Pointers
Declaring the Array Size with a Non-Constant Variable
Sort Array by First Item in Subarray C++
Redirect Stdout/Stderr to a String
How to Solve "Unresolved Inclusion: <Iostream>" in a C++ File in Eclipse Cdt
May I Take the Address of the One-Past-The-End Element of an Array