我正在尝试开始使用 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/