2013-06-06 2 views
0

sqlite 데이터베이스에 링크하려는 C++ 광고를 처음 사용했습니다. 자습서를 따르고 있는데 sqlite3_open 오류가 발생했습니다. 정의되지 않은 참조입니다. 내가 뭘 잘못하고 있니?C++ QTCreator 5.0 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 failed\n"); 
return -1; 
} 
printf("Connection successful\n"); 
return 1; 
} 

.PRO 파일

#------------------------------------------------- 
# 
# 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 
+0

(1) 전체 오류 메시지와 (2) Qt 프로젝트 (* .pro) 파일을 게시 하시겠습니까? – Geier

+0

정보를 추가했습니다. – Talon06

답변

3

당신이 (아마도 가장 적합한) 시스템의 SQLite는 버전 전년도 연결하려면 .pro- 파일 :

LIBS += -lsqlite3 

그리고 그것이어야합니다.

또한 sqlite 소스 ("호출"이라고도 함)를 다운로드하고 .c 파일을 프로젝트에 추가 할 수 있습니다. 그렇게한다면 다운로드 한 헤더 파일을 사용해야합니다. 그러나 코드의 시스템 헤더 파일 때문에 시스템의 라이브러리 버전을 사용하고 싶다고 가정합니다.