Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

c++ - Error: undefined reference to `sqlite3_open'

I'm trying to get started with the C++ API for SQLite.

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

using namespace std;

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

    return 0;
}   

Compiling this using the command "g++ main.cpp" gives the following error:

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

What could have gone wrong? Hasn't sqlite3 properly installed in the server I'm compiling this in?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to link the sqlite3 library along with your program:

g++ main.cpp -lsqlite3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...