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

标签 c++ sqlite

解决方案:我刚刚将 -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++ - 如何在我的 C++ 应用程序中编译 sqlite3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8702302/

相关文章:

c++ - 如何将可变参数传递给模板?

python - django 聊天机器人网站中从 Sqlite3 到 Mysql

android - 错误更新或从数据库中删除; "could not execute method"

c++ - 对于非重复项,最有效的标准容器是什么?

python - 如何在不必等待输出完成的情况下继续迭代?

android - 在 android 中加入表格

iphone - 将图像存储到sqlite数据库中

c++ - CUDA 推力的 2D device_vector 错误

c++ - 为什么 “delete *this” 会编译?

c++ - 预先为 C++ 应用程序分配内存