Link error with my own C++ library -
this first time trying make simple library. worked in ubuntu 12.04 g++ 4.6.3. here problem:
[[mylib.cpp]] #include<sqlite3.h> void mylib::blahblah() {...} void mylib::evenmoreblah() {...} ... [[mylib.h]] #include <...> class mylib { ... };
then made lib by:
gcc -c -wall -fpic mylib.cpp gcc -shared -o libmylib.so mylib.o
i used library in single test.cpp contains main(). put libmylib.so in ./libdir, , compiled using:
g++ -g test.cpp -o test -lpthread -l/usr/local/lib -lsqlite3 -l./libdir -lmylib
the error got:
./libdir/libmylib.so: undefined reference `sqlite3_close' ./libdir/libmylib.so: undefined reference `sqlite3_exec' ./libdir/libmylib.so: undefined reference `sqlite3_free' ./libdir/libmylib.so: undefined reference `sqlite3_open'
you link -lsqlite3
shared library with
gcc -shared mylib.o -o libmylib.so -lsqlite3
if that, don't need explicitly link -lsqlite3
program, won't harm.
and order of linking arguments program important:
g++ -wall -g test.cpp -o mytest \ -l./libdir -lmylib -l/usr/local/lib -lsqlite3 -lpthread
it should go higher-level libraries lower-level (i.e. system) ones. , don't forget -wall
warnings compiler, useful.
read program library howto.
ps. don't call program test
shell builtin (and standard /usr/bin/test
). use other name.
Comments
Post a Comment