繁体   English   中英

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

[英]Howto compile sqlite3 in my C++ app?

解决方案:我刚刚在我的makefile中添加了-lpthread -ldl标志,它可以工作! 不知道为什么,但我很幸运,因为我在努力避免手工编译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'

这意味着我需要在尝试与应用程序分开编译sqlite3时添加-lpthread标志。 好吧,我被卡住了。

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

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

gcc -c -o sqlite3.o sqlite3.c

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM