[英]Compiling of SQlite3 in C++
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. 其中sqlite3是我从sqlite-amalgamation-3071100.zip收到的源文件的文件夹,-I是包含源的标志。
This archive contains : shell.c, sqlite3.c, sqlite3.h, sqlite3ext.h. 该存档包含: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(...); 该程序只包含#include和函数调用sqlite3_open(...);
I can compile all fine if I make "sudo apt-get install libsqlite3-dev" and compile program with command 如果我制作“sudo apt-get install libsqlite3-dev”并使用命令编译程序,我可以编译好
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! 但我想解决这个问题,因为我不想在另一台计算机上安装一些库,我没有权限!
My makefile for sqlite shell and c++ api test: 我的sqlite shell和c ++ api测试的makefile:
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 . 从http://www.sqlite.org/download.html下载sqlite amalgamation。
Include any reference to sqlite as extern "C", since sqlite is written in C. 包含对sqlite的任何引用为extern“C”,因为sqlite是用C语言编写的。
Create the sqlite library with "gcc -c sqlite3.c". 使用“gcc -c sqlite3.c”创建sqlite库。
Link your program to the newly created library with "g++ main.c sqlite3.o" 使用“g ++ main.c sqlite3.o”将程序链接到新创建的库
You will need to compile sqlite3
with gcc
. 您将需要编译sqlite3
与gcc
。 I tried g++
and the result was hundreds of errors and warnings. 我尝试了g++
,结果是数以百计的错误和警告。
Perhaps sqlite3
shoule be written in such a way that it would compile with a C++ compiler. 也许sqlite3
shoule的编写方式可以用C ++编译器编译。 C++ compilers are much choosier and enforce types and such much better than a C compiler. C ++编译器更加挑剔并强制执行类型,并且比C编译器更好。
在具有MinGW32的Windows上,通过以下方式编译动态链接库:
gcc -shared sqlite3.c -o sqlite3.dll
The following worked for me on Ubuntu: 以下在Ubuntu上为我工作:
gcc -o test test.c sqlite3.c -lpthread -idl gcc -o test test.c sqlite3.c -lpthread -idl
The reference as stated below: 参考如下:
https://www.sqlite.org/draft/howtocompile.html https://www.sqlite.org/draft/howtocompile.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.