pirad
pirad

Reputation: 205

How to use SQLite with c++ on Ubuntu? (undefined reference error)

I want to use SQLite with c++ on Ubuntu. I chose to try the example from https://www.sqlite.org/quickstart.html. But when running c++ test.cpp -o test I get the error:

/tmp/ccTwwjKw.o: In function `main':
test.cpp:(.text+0xf1): undefined reference to `sqlite3_open'
test.cpp:(.text+0x106): undefined reference to `sqlite3_errmsg'
test.cpp:(.text+0x12e): undefined reference to `sqlite3_close'
test.cpp:(.text+0x15d): undefined reference to `sqlite3_exec'
test.cpp:(.text+0x18f): undefined reference to `sqlite3_free'
test.cpp:(.text+0x19b): undefined reference to `sqlite3_close'
collect2: ld gab 1 als Ende-Status zurück

I think the Problem is the same as here: Sqlite undefined reference to `sqlite3_open' error in Netbeans C++ on Ubuntu, Integrating SQLite into Netbeans C++ Ubuntu. But I have no make file and I don't use netbeans.

Upvotes: 2

Views: 5607

Answers (1)

mathematician1975
mathematician1975

Reputation: 21351

This is a linker error and you are not linking to any libraries. Link to the correct libraries using -llibname where libname is the name of your library with lib removed from the start. For example if the libname is libsqlite3.so try adding -lsqlite3 at the end of your compilation step. Of course you need to also provide the path to that library if it is in a non standard place using the -L/path/to/lib option and obviously you will need to have installed the relevant library first.

Upvotes: 3

Related Questions