我正在为我的项目使用 Code::Blocks IDE。
到目前为止,我下载了 sqlite3 合并文件,使用 make install
安装它们并将 libsqlite3.a 库链接到我的项目
project->build options->linker settings 并添加了 libslite3.a 文件。
现在,当我尝试构建我的项目时,我遇到了一些错误,例如 undefined reference to pthread_mutex_trylock
或 undefined reference to pthread_create
。
我在我的 main 中包含了 pthread
、thread
、mutex
header ,我添加了选项 -lpthread
和 pthread
或者在 project->build options->other copiler options 我仍然得到同样的错误.
最佳答案
-l<library>
是链接器选项,而不是编译器选项,所以在 Code::Blocks
它进入其他链接器选项
删除 -lpthread
从编译器选项并将其添加到链接器
选项可能就足够了。
然而,启用 pthreads
的正确、便携的方法GCC 中的多线程是
添加选项 -pthread
(不是 -lpthread
)到两个编译器选项:-
项目->构建选项->编译器设置 -> 其他编译器选项
和链接器选项:
项目->构建选项->链接器设置 -> 其他链接器选项
这个选项告诉编译器做正确的事情
生成 pthreads
兼容的代码,并告诉链接器做正确的事情
将其与主机平台的 POSIX 线程库链接。
使用pthreads
在你的程序中,#include <pthreads.h>
关于c++ - 即使使用 -lpthread 选项,Sqlite3 库也会出现线程错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41662375/