Compiling of SQlite3 in C++
c++, compilation, g++, sqlite
Solution
- Step1: compile sqlite3.c to sqlite3.o by gcc
- Step2: compile your c++ code together with sqlite3.o by g++
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
Problem
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!