I compile code this way:
g++ main.cpp -I sqlite3
where sqlite3 is a folder with source files which I received from sqlite-amalgamation-3071100.zip, -I is flag for including sources.
This archive contains : shell.c, sqlite3.c, sqlite3.h, sqlite3ext.h.
This is what I receive:
undefined reference to `sqlite3_open'
The program just contain #include and call of function sqlite3_open(...);
I can compile all fine if I make "sudo apt-get install libsqlite3-dev" and compile program with command
g++ main.cpp -lsqlite3
But I want to solve that problem, because I do not want to have to install some libraries on another computer, I do not have access for that!
First download the preprocessed source code from http://www.sqlite.org/ sqlite_source. zip. This archive contains a set of C source and header files that are ready to be passed to a C compiler. To build the library, just compile all of the files.
h: The header files that accompanies sqlite3. c and defines the C-language interfaces to SQLite.
The amalgamation contains everything an application needs to embed SQLite. Combining all the code for SQLite into one big file makes SQLite easier to deploy — there is just one file to keep track of.
My makefile for sqlite shell and c++ api test:
1 CXX = g++
2 cc = gcc
3
4 LIB = -lpthread -ldl
5 BIN = sqlite apiTest
6
7 all : $(BIN)
8 sqlite : sqlite3.c shell.c
9 $(cc) -o $@ $^ $(LIB)
10 apiTest : apiTest.cpp sqlite3.o
11 $(CXX) -o $@ $^ $(LIB)
12 sqlite3.o : sqlite3.c
13 $(cc) -o $@ -c $^
14
15 clean :
16 rm -f $(BIN)
17
18 .PHONY: all, clean
Download the sqlite amalgamation from http://www.sqlite.org/download.html.
Include any reference to sqlite as extern "C", since sqlite is written in C.
Create the sqlite library with "gcc -c sqlite3.c".
Link your program to the newly created library with "g++ main.c sqlite3.o"
You will need to compile sqlite3
with gcc
. I tried g++
and the result was hundreds of errors and warnings.
Perhaps sqlite3
shoule be written in such a way that it would compile with a C++ compiler. C++ compilers are much choosier and enforce types and such much better than a C compiler.
The following worked for me on Ubuntu:
gcc -o test test.c sqlite3.c -lpthread -idl
The reference as stated below:
https://www.sqlite.org/draft/howtocompile.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With