在 vscode for c++ 中使用 sqlite3(未定义对 'xxx' 的引用)(我使用了 -lsqlite3)
Use sqlite3 in vscode for c++(undefined reference to `xxx')(I have use -lsqlite3)
我为这个问题发疯了。我根据教程下载了sqlite3的源代码和预编译文件,用vs编译,得到了sqlite3.lib
和sqlite3.exp
文件,放在C: sql
文件夹中。然后我在 vscode 中创建项目,并将sqlite3.h
放在项目的根目录中,并创建了以下测试代码。
#include "sqlite3.h"
#include <stdio.h>
#include <stdlib.h>
#pragma warning(disable : 4996)
#pragma comment(lib, "c:\sql\sqlite3.lib")
int main() {
sqlite3 *db = NULL;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open("Student.db", &db);
if (rc) {
fprintf(stderr, "Can't open database: %sn", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
} else
printf("open mydata successfully!n");
sqlite3_close(db);
system("pause");
return 0;
}
我的tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "gdb",
"type": "shell",
"command": "g++",
"args": [
"${file}",
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe",
"-LC:\sql",
// "${fileDirname}\src\Account.cpp",
// "${fileDirname}\src\Person.cpp",
// "${fileDirname}\src\Date.cpp",
// "${fileDirname}\src\System.cpp",
// "${fileDirname}\src\Administrator.cpp",
"-lsqlite3",
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
但是无论我如何修改tasks.json文件,我仍然得到以下结果。我真的太迷茫了。谁能帮我解决这个问题?
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:UsersDrewAppDataLocalTempccUXavQh.o:test.cpp:(.text+0x2e): undefined reference to `sqlite3_open'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:UsersDrewAppDataLocalTempccUXavQh.o:test.cpp:(.text+0x45): undefined reference to `sqlite3_errmsg'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:UsersDrewAppDataLocalTempccUXavQh.o:test.cpp:(.text+0x6d): undefined reference to `sqlite3_close'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:UsersDrewAppDataLocalTempccUXavQh.o:test.cpp:(.text+0x91): undefined reference to `sqlite3_close'
collect2.exe: error: ld returned 1 exit status
我个人下载了sqlite-amalgamation源代码并将其编译为常规源文件。SQLite使它变得非常简单,你应该没有问题 https://www.sqlite.org/download.html
当我不需要时,我不会弄乱静态/动态库。问题可能是由于哪个编译器编译了库(即ms编译器,mingw,clang等(。您可能会混合它们导致错误。我怀疑预编译使用的是 ms 编译器。从内存中,clang可以使用使用ms编译器编译的库(clang取决于它(。Mingw 不依赖于它,也不会使用 MS 编译的库
相关文章:
- 在 vscode for c++ 中使用 sqlite3(未定义对 'xxx' 的引用)(我使用了 -lsqlite3)
- Eclipse/CDT_C++给出"语义错误_"类型XXX无法解决"。项目运行
- 如何正确转发声明结构"using XXX"?
- 链接器错误:在包含 .so lib 后未定义对 xxx 的引用
- 我不断收到对项目"xxx"的错误未定义引用
- 如何计算字符串 c++ 中的"xxx"数?
- pybind11:属性错误:尝试从 py 文件运行函数时,模块'XXX'没有属性'YYY'
- 将硬盘驱动器上的 BIT XXX 从 0 更改为 1
- lnk1114无法覆盖原始文件"xxx.lib",错误代码32
- C++ #include<XXX.h>相当于 Python 导入的 XXX 作为 X
- 在模板元编程中使用"struct xxx<>::val"导致错误
- 如何使用 /dev/xxx 路径中的C++获取 Ubuntu 中设备的 USB VID、PID 和序列号
- 检测到"运行时库"的不匹配LNK2038:值"MT_StaticRelease"与 xxx.obj 中的值"MTd_StaticDebug"不匹配
- Qt-creator 错误: C1083: 无法打开包含文件: 'xxx.h': 没有这样的文件或目录
- "passing const XXX as this disregards qualifiers"解释 ?
- 错误假设在GCC上从过载函数中键入XXX
- 错误:将'xxx'作为'xxx'丢弃限定符的参数传递'this' [-允许]
- 有什么区别:在命名空间 yyy 外部和内部使用 namespae xxx?
- 德尔福仿制药:E2037:'XXX'声明与以前的声明不同
- 如何避免int(xxx)_t之间的重叠,并使我的代码正确