sqlite error:undefined swmbol:pthread_mutex_lock
sqlite error:undefined swmbol:pthread_mutex_lock
我正在尝试学习 sqlite c api 并编写了一些代码来测试多个数据库连接到同一个数据库文件。这个文件编译没有错误但是当我 运行 我得到:
./sq: symbol lookup error: ./sq: undefined symbol: pthread_mutex_lock, version GLIBC_2.2.5
代码如下:
#include "../sqlite3.h"
int main()
{
sqlite3 **my_db;
sqlite3 **my_db2;
sqlite3_stmt **ppStmt;
sqlite3_stmt **ppStmt2;
int res;
double res2;
int rc;
char pzTail[100];
sqlite3_open("../test.db", my_db);
sqlite3_open("../test.db", my_db2);
sqlite3_prepare_v2(*my_db, "select * from tbl1 where one='goog';", 50, ppStmt, &pzTail);
rc = sqlite3_step(*ppStmt);
if (rc != SQLITE_OK) {
fprintf(stderr, "Failed to fetch data: %s\n", sqlite3_errmsg(my_db));
sqlite3_close(my_db);
return 1;
}
res = sqlite3_column_int(*ppStmt, 1);
printf("we have %d\n",res);
sqlite3_step(*ppStmt);
res = sqlite3_column_int(*ppStmt, 1);
printf("we have %f\n",res);
sqlite3_step(*ppStmt);
res = sqlite3_column_int(*ppStmt, 1);
printf("we have %d\n",res);
sqlite3_finalize(*ppStmt);
sqlite3_close(*my_db);
return 0;
}
当我 运行 没有第二个 sqlite3_open 语句的代码时,一切都是正确的,但是当我添加它时,上面提到的错误出现在 运行 时间,gdb 显示:
(gdb) run
Starting program: .../sqlite-amalgamation3130000/playground/sq
dl-debug.c:74: No such file or directory.
dl-debug.c:74: No such file or directory.
dl-debug.c:74: No such file or directory.
dl-debug.c:74: No such file or directory.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
dl-debug.c:74: No such file or directory.
dl-debug.c:74: No such file or directory.
(process 4636) exited with code 0177]
出于某种原因,我使用 sqlite_amalgamation 源代码的副本而不是系统安装的 sqlite 库编译此代码:
gcc -g -I.. sqlite_c_api.c ../sqlite3.c -ldl -pthread -o sq
并且我之前在某些多线程应用程序的某些机器上尝试过'pthread_mutex_lock()'。
is/are 我的错误在哪里?
我解决了。错误是因为当我用 * 指针替换它们并相应地更改代码时,我使用了 ** 指针,一切似乎都是正确的。
我正在尝试学习 sqlite c api 并编写了一些代码来测试多个数据库连接到同一个数据库文件。这个文件编译没有错误但是当我 运行 我得到:
./sq: symbol lookup error: ./sq: undefined symbol: pthread_mutex_lock, version GLIBC_2.2.5
代码如下:
#include "../sqlite3.h"
int main()
{
sqlite3 **my_db;
sqlite3 **my_db2;
sqlite3_stmt **ppStmt;
sqlite3_stmt **ppStmt2;
int res;
double res2;
int rc;
char pzTail[100];
sqlite3_open("../test.db", my_db);
sqlite3_open("../test.db", my_db2);
sqlite3_prepare_v2(*my_db, "select * from tbl1 where one='goog';", 50, ppStmt, &pzTail);
rc = sqlite3_step(*ppStmt);
if (rc != SQLITE_OK) {
fprintf(stderr, "Failed to fetch data: %s\n", sqlite3_errmsg(my_db));
sqlite3_close(my_db);
return 1;
}
res = sqlite3_column_int(*ppStmt, 1);
printf("we have %d\n",res);
sqlite3_step(*ppStmt);
res = sqlite3_column_int(*ppStmt, 1);
printf("we have %f\n",res);
sqlite3_step(*ppStmt);
res = sqlite3_column_int(*ppStmt, 1);
printf("we have %d\n",res);
sqlite3_finalize(*ppStmt);
sqlite3_close(*my_db);
return 0;
}
当我 运行 没有第二个 sqlite3_open 语句的代码时,一切都是正确的,但是当我添加它时,上面提到的错误出现在 运行 时间,gdb 显示:
(gdb) run
Starting program: .../sqlite-amalgamation3130000/playground/sq
dl-debug.c:74: No such file or directory.
dl-debug.c:74: No such file or directory.
dl-debug.c:74: No such file or directory.
dl-debug.c:74: No such file or directory.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
dl-debug.c:74: No such file or directory.
dl-debug.c:74: No such file or directory.
(process 4636) exited with code 0177]
出于某种原因,我使用 sqlite_amalgamation 源代码的副本而不是系统安装的 sqlite 库编译此代码:
gcc -g -I.. sqlite_c_api.c ../sqlite3.c -ldl -pthread -o sq
并且我之前在某些多线程应用程序的某些机器上尝试过'pthread_mutex_lock()'。
is/are 我的错误在哪里?
我解决了。错误是因为当我用 * 指针替换它们并相应地更改代码时,我使用了 ** 指针,一切似乎都是正确的。