如何在Ubuntu上使用带有c++的SQLite?(未定义的引用错误)

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

本文关键字:SQLite 未定义 错误 引用 c++ Ubuntu      更新时间:2023-10-16

我想在Ubuntu上使用带有c++的SQLite。我选择从https://www.sqlite.org/quickstart.html.但当运行c++ test.cpp -o test时,我得到了错误:

/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

我认为问题与这里相同:Sqlite未定义引用`sqlite3_open';Ubuntu上的Netbeans C++中的错误,将SQLite集成到Netbeans C++Ubuntu中。但我没有make文件,也不使用netbeans。

这是一个链接器错误,您没有链接到任何库。使用-libname链接到正确的库,其中libname是从一开始就删除了lib的库的名称。例如,如果libname是libsqlite3,那么请尝试在编译步骤结束时添加-lsqlite3。当然,如果该库位于使用-L/path/to/lib选项的非标准位置,您还需要提供该库的路径,而且显然您需要先安装相关库。