简体   繁体   English

错误:对“sqlite3_open”的未定义引用

[英]Error: undefined reference to `sqlite3_open'

I'm trying to get started with the C++ API for 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;
}   

Compiling this using the command "g++ main.cpp" gives the following error:使用命令“g++ main.cpp”编译它会出现以下错误:

/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?我正在编译的服务器中没有正确安装 sqlite3 吗?

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

g++ main.cpp -lsqlite3

You need to adjust your linker flags to link in the sqlite3 library.您需要调整链接器标志以在sqlite3库中进行链接。 Libraries are usually installed in /usr/lib or /usr/lib64库通常安装在/usr/lib/usr/lib64

Alternatively, you can copy the sqlite3.c file to your project directory and compile it as part of the g++ command:或者,您可以将sqlite3.c文件复制到您的项目目录并将其编译为g++命令的一部分:

g++ main.cpp sqlite3.c 

as per: http://sqlite.org/cvstrac/wiki?p=HowToCompile根据: http : //sqlite.org/cvstrac/wiki?p=HowToCompile

First step: Install all library sqlite3 with the command:第一步:使用以下命令安装所有库 sqlite3:

        sudo apt-get install libsqlite3-dev

With that you can use #include <sqlite3.h> in a programm of C or C++ .有了它,您可以在CC++程序中使用#include <sqlite3.h>

Second step: To compile the program by console:第二步:通过控制台编译程序:

C++: C++:

        g++ program.cpp -o executable -lsqlite3

        ./executable

C: C:

        gcc program.c -o executable -lsqlite3

        ./executable

在命令行或 Open IDE -> project -> properties -> locate lib file for sqlite3 中将您的程序链接到 lib g++ yourProgram.c -lsqlite3 。

HELLO EVERYONE大家好

if you using Devcpp如果你使用Devcpp

1. you just need to add the sqlite3.dll file in the project folder. 1.只需要在项目文件夹中添加sqlite3.dll文件即可。

2. Goto Compiler option in Tools >> 2.工具中的 Goto Compiler 选项 >>

3. just write sqlite3.dll next to >> Add the following commands when calling compiler 3.只需在>>旁边写sqlite3.dll调用编译器时添加以下命令

Screen shot截屏

Compile using command使用命令编译

NOTE : you need to install MinGW (compiler)注意您需要安装 MinGW(编译器)

g++ file.cpp -o output.exe sqlite3.dll

compile using VS使用VS编译

You need to define sqlite3.dll in linker in project properties您需要在项目属性的链接器中定义sqlite3.dll

HAVE A NICE DAY

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对“sqlite3_open”的未定义引用 - undefined reference to `sqlite3_open' C++ SQLite3 错误 - 未定义对“sqlite3_open”的引用 - C++ SQLite3 Error - undefined reference to `sqlite3_open' 未定义对“sqlite3_open”的引用。 我没主意了 - undefined reference to `sqlite3_open'. I out of ideas 在Ubuntu上的Netbeans C ++中,Sqlite未定义对“ sqlite3_open”错误的引用,将SQLite集成到Netbeans C ++ Ubuntu中 - Sqlite undefined reference to `sqlite3_open' error in Netbeans C++ on Ubuntu, Integrating SQLite into Netbeans C++ Ubuntu C ++ QTCreator 5.0 SQLite3_Open未定义引用 - C++ QTCreator 5.0 SQLite3_Open Undefined Refernce sqlite3_open无法在线打开文件 - sqlite3_open cannot open file at line 将QString传递给sqlite3_open的编码问题 - Trouble with encoding passing a QString to sqlite3_open 尝试在Visual Studio 2013中使用sqlite3_open进行编译时出错 - Error when trying to compile using sqlite3_open in Visual Studio 2013 sqlite3_open - 检查文件是否为sqlite3数据库的问题 - sqlite3_open - problems checking if a file is a sqlite3 database 当我在x64位模式下编译MFC应用程序且在win32模式下没有问题时,错误lnk2019无法解析符号sqlite3_open - error lnk2019 unresolved symbol sqlite3_open when i compile my MFC application in x64bit mode and no issue in win32 mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM