如何在我的c++应用程序中编译sqlite3

Howto compile sqlite3 in my C++ app?

本文关键字:编译 sqlite3 应用程序 c++ 我的      更新时间:2023-10-16

解决方案:我只是添加了-lpthread -ldl标志到我的makefile和它的工作!不知道为什么,但我很幸运地避免了手工编译sqlite3,因为我正在尝试…嗯,不管怎样,有些答案还是不错的。谢谢大家,我去给你们喝点茶。

三个月前我能够找到如何做到这一点,但现在它不工作。我有一个巨大的c++应用程序,我需要嵌入sqlite3代码,但我不能编译它。我使用如下代码:

gcc sqlite3.c -lpthread -ldl -o ./sqlite3.o

但它不起作用;我试过很多不同的方法。我有一个makefile,我在其中添加了sqlite3.h和sqlite3.c文件。当我在应用程序的特定文件夹中执行make && make install时,它显示错误:

.libs/sqlite3.o: In function `pthreadMutexTry':
/home/.../client/sqlite3.c:17769: undefined reference to `pthread_mutex_trylock'
.libs/sqlite3.o: In function `pthreadMutexAlloc':
/home/.../client/sqlite3.c:17637: undefined reference to `pthread_mutexattr_init'
/home/.../client/sqlite3.c:17638: undefined reference to `pthread_mutexattr_settype'
/home/.../client/sqlite3.c:17640: undefined reference to `pthread_mutexattr_destroy'

这意味着我需要添加-lpthread标志,当尝试从应用程序单独编译sqlite3时。好吧,我卡住了。

链接时命令行上库的顺序很重要。把库(-lpthread -ldl)放在最后。

您需要-c标志来生成目标文件,而不是链接。并跳过库-在链接整个应用程序时传递它们。

gcc -c -o sqlite3.o sqlite3.c