You could link -lsqlite3
into your shared library with
gcc -shared mylib.o -o libmylib.so -lsqlite3
If you do that, you don't need to explicitly link -lsqlite3
to your program, but that won't harm.
and the order of linking arguments for your program is important:
g++ -Wall -g test.cpp -o mytest \
-L./libdir -lmylib -L/usr/local/lib -lsqlite3 -lpthread
it should go from higher-level libraries to lower-level (i.e. system) ones. And don't forget -Wall
to get almost all warnings from the compiler, which is very useful.
Read the Program Library HowTo.
PS. Don't call your program test
which is a shell builtin (and the standard /usr/bin/test
). Use some other name.