c++ - 错误 : undefined reference to `sqlite3_open'

标签 c++ sqlite

我正在尝试开始使用 SQLite 的 C++ API。

#include <iostream>
#include <sqlite3.h>

using namespace std;

int main()
{
    sqlite3 *db;
    if (sqlite3_open("ex1.db", &db) == SQLITE_OK)
        cout << "Opened db successfully\n";
    else
        cout << "Failed to open db\n";

    return 0;
}   

使用命令“g++ main.cpp”编译它会出现以下错误:

/tmp/ccu8sv4b.o: In function `main':
main.cpp:(.text+0x64): undefined reference to `sqlite3_open'
collect2: ld returned 1 exit status

可能出了什么问题?我正在编译它的服务器中没有正确安装 sqlite3 吗?

最佳答案

您需要将 sqlite3 库与您的程序一起链接:

g++ main.cpp -lsqlite3

关于c++ - 错误 : undefined reference to `sqlite3_open' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9389344/

相关文章:

c++ - 在 OpenGL 中渲染纹理 1 到 1

ios - 使用 Core Data/sqlite 正确收集元数据/对象数据

android - java.lang.IllegalArgumentException : Cannot bind argument at index 1 because the index is out of range. 该语句有 0 个参数

sqlite - 如何在使用 SQLite 的 ASP.NET Core Web 应用程序的发布版本中为 ApplicationDbContext 应用现有迁移

Python:在 Sqlite3 中插入​​ UUID 值

android - 是否可以将 PreferenceActivity 与 SQLite 而不是 res/xml 一起使用?

c++ - 是否可以在运行时确定指针指向 C++ 类还是指向 Objective-C 类?

python - 带有类型推导的 swig python 模板函数

c++ - 将Lambda传递给std::find

c++ - 在 C++ 中使用 pthread 时出现编译错误