gpt4 book ai didi

c++ - Sqlite undefined reference to `sqlite3_open' error in Netbeans C++ on Ubuntu, Integrating SQLite into Netbeans C++ Ubuntu

转载 作者:行者123 更新时间:2023-11-28 01:10:44 28 4
gpt4 key购买 nike

我正在尝试在我的 Netbeans C++ 中使用 Sqlite 并遵循此处的教程 http://www.dreamincode.net/forums/topic/122300-sqlite-in-c/

当我构建它时,它给了我对“sqlite3_open”和其他 sqlite3 函数的 undefined reference 。我也包含了 sqlite3.h。我在这里错过了什么?

当我在项目属性中将链接器添加到静态库 libsqlite3.a 时,我的 undefined reference 错误消失了,但现在它给了我

/usr/lib/libsqlite3.a(sqlite3.o): 在函数 pthreadMutexTry' 中:
/usr/lib/libsqlite3.a(sqlite3.o): 在函数中
pthreadMutexAlloc':/usr/lib/libsqlite3.a(sqlite3.o): 在函数 pthreadMutexAlloc' 中:
/usr/lib/libsqlite3.a(sqlite3.o): 在函数中
pthreadMutexAlloc':/usr/lib/libsqlite3.a(sqlite3.o): 在函数 unixDlError':
/usr/lib/libsqlite3.a(sqlite3.o): 在函数中
findLockInfo':/usr/lib/libsqlite3.a(sqlite3.o): 在函数 findLockInfo' 中:
/usr/lib/libsqlite3.a(sqlite3.o): 在函数中
unixDlSym':/usr/lib/libsqlite3.a(sqlite3.o):在函数 unixDlClose' 中:
/usr/lib/libsqlite3.a(sqlite3.o): 在函数中
unixDlOpen':collect2: ld 返回 1 退出状态make[2]: * [dist/Debug/GNU-Linux-x86/cddb] 错误 1make[1]: * [.build-conf] 错误 2make: *** [.build-impl] 错误 2

如果我包含 sqlite3ext.h,我会得到main.cpp:20: 错误:‘sqlite3_api’未在此范围内声明

最佳答案

(请参阅下面的编辑)

不确定 C++ 在 NetBeans 中的工作方式,但您添加的 libsqlite3.a 看起来不错。现在,如果您有一个 Makefile,您可以编辑它并定义(或编辑)LDFLAGS 变量,并将其作为选项传递给链接器...

SQLite 在其默认配置中需要与 libdllibpthread 链接,这就是为什么您可能需要将 -ldl -lpthread 添加到您的链接选项。

例如(如果这在 NetBeans 中可行)将其添加到您的 Makefile 中:

LDFLAGS= -ldl -lpthread

在我的项目中,我是这样使用它的:

target: $(OBJ)
gcc $(LDFLAGS) $(OBJ) -o $@

编辑:

实际上也可以在 GUI 中添加链接器选项,而无需手动编辑 Makefile :

在子菜单 Configuration Properties -> Linker -> Command Line 中,只需在“Additional options”中添加 -ldl -lpthread 并重新编译您的项目。

关于c++ - Sqlite undefined reference to `sqlite3_open' error in Netbeans C++ on Ubuntu, Integrating SQLite into Netbeans C++ Ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3463438/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com