c++ QTCreator 5.0 SQLite3_Open未定义引用
C++ QTCreator 5.0 SQLite3_Open Undefined Refernce
我是新的c++和试图链接到sqlite数据库。我正在遵循一个教程,我得到一个sqlite3_open错误未定义的引用。我做错了什么?
#include "database.h"
#include<stdio.h>
#include<sqlite3.h>
#include<stdlib.h>
database::database()
{
}
int database::test()
{
int retval;
// A prepered statement for fetching tables
sqlite3_stmt *stmt;
// Create a handle for database connection, create a pointer to sqlite3
sqlite3 *handle;
// try to create the database. If it doesnt exist, it would be created
// pass a pointer to the pointer to sqlite3, in short sqlite3**
retval = sqlite3_open("CC.sqlite",&handle);
// If connection failed, handle returns NULL
if(retval)
{
printf("Database connection failedn");
return -1;
}
printf("Connection successfuln");
return 1;
}
。箴文件
#-------------------------------------------------
#
# Project created by QtCreator 2013-05-31T09:22:09
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = CC_Herd_Manager
TEMPLATE = app
SOURCES += main.cpp
mainwindow.cpp
animal.cpp
email.cpp
owner.cpp
phone.cpp
equipment.cpp
../CC_Cpp/cc_number.cpp
../CC_Cpp/cc_date.cpp
../CC_Cpp/cc_timestamp.cpp
../CC_Cpp/cc_address.cpp
database.cpp
HEADERS += mainwindow.h
animal.h
email.h
owner.h
phone.h
equipment.h
../CC_Cpp/cc_number.h
../Cpp/CC_Cpp/cc_date.h
../Cpp/CC_Cpp/cc_timestamp.h
../Cpp/CC_Cpp/cc_address.h
database.h
FORMS += mainwindow.ui
OTHER_FILES +=
DB_Install
误差/home/mongo/Cpp/CC_Herd_Manager/database.o:-1: In function `database::test()':
/home/mongo/Cpp/CC_Herd_Manager/database.cpp:23: error: undefined reference to `sqlite3_open'
:-1: error: collect2: error: ld returned 1 exit status
如果您想链接到系统的sqlite版本(这可能是最好的),您必须在.pro文件中添加以下行:
LIBS += -lsqlite3
应该是这样。
您还可以下载sqlite源代码(他们称之为"合并")并将.c文件添加到您的项目中。如果这样做,您也应该使用下载的头文件。但是因为您在代码中使用了系统的头文件,所以我假设您希望使用系统的库版本,我推荐使用。
相关文章:
- 编译C++时未定义的引用
- vscode g++链路故障:体系结构x86_64的未定义符号
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 不知道某个东西是否被忽略会引入未定义的行为吗
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 未定义的引用在哪里
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- c++11评估顺序(未定义的行为)
- 使用mysql c++连接器的未定义引用
- 从python调用openMP共享库时,未定义opnMP函数
- 在 Mac 上使用 CMAKE 将 FFTW 和 FFTWPP 链接到项目中时未定义的符号
- Cmake 链接问题:未定义对 Button::mousePressEvent(QGraphicsSceneMouseE
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 具有外部"c"和程序集的未定义函数
- 此增量后语句是否会导致未定义的行为?
- 尝试调用 .h 文件中定义的变量时出现变量未定义错误
- 在C++中使用内联方法时出现未定义的符号错误
- Open AL 的函数在 ubuntu 中使用 g++ 编译时给出未定义引用的错误