I have a static library, libsqlite3.a, that i want to link to my small program.
my make file is as shown below:
CPP = g++
sources = main.cpp
objects = main.o
included = -IC:/SQLite-lib/include
linked = -LC:/SQLite-lib/ -lsqlite3
main : $(objects)
$(CPP) $(linked) $(objects) -o main
main.o : $(sources)
$(CPP) $(included) -c main.cpp
I keep getting this kind of error message:
g++ -LC:/SQLite-lib/libsqlite3.a main.o -o main
main.o:main.cpp:(.text+0x42): undefined reference to `sqlite3_open'
main.o:main.cpp:(.text+0x7d): undefined reference to `sqlite3_close'
main.o:main.cpp:(.text+0xe7): undefined reference to `sqlite3_close'
collect2: ld returned 1 exit status
make: *** [main] Error 1
What am I doing wrong? I use Win XP SP3, GCC 4.6.2.
You must always place libraries after the files you link. Change the linking line in the makefile to:
That should work.