Reputation: 1621
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!
Upvotes: 19
Views: 23905
Reputation: 11
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
Upvotes: 1
Reputation: 1
On Windows with MinGW32 compile a dynamic link library by:
gcc -shared sqlite3.c -o sqlite3.dll
Upvotes: 0
Reputation: 163
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
Upvotes: 16
Reputation: 21
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.
Upvotes: 2
Reputation: 81
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"
Upvotes: 5