gpt4 book ai didi

ios - 架构 i386 : "_sqlite3_open", 的 undefined symbol 引用自:错误

转载 作者:技术小花猫 更新时间:2023-10-29 10:13:36 24 4
gpt4 key购买 nike

我已经创建了一个数据库类并打包了一些方法。但是,一旦构建项目...

Undefined symbols for architecture i386:
"_sqlite3_open", referenced from:
-[MyDataBase openOrCreateDatabase:] in MyDataBase.o
"_sqlite3_exec", referenced from:
-[MyDataBase createTable:] in MyDataBase.o
-[MyDataBase InsertTable:] in MyDataBase.o
-[MyDataBase UpdataTable:] in MyDataBase.o
-[MyDataBase querryTableByCallBack:] in MyDataBase.o
"_sqlite3_close", referenced from:
-[MyDataBase closeDatabase] in MyDataBase.o
"_sqlite3_get_table", referenced from:
-[MyDataBase querryTable:] in MyDataBase.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这里有一些关键的方法:

创建数据库:

-(BOOL)openOrCreateDatabase:(NSString*)dbName 
{
self.m_dbName = dbName;
NSArray *path =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [path objectAtIndex:0];
if(sqlite3_open([[documentsDirectory stringByAppendingPathComponent:dbName] UTF8String],&m_sql) !=SQLITE_OK)
{
NSLog(@"创建数据库失败");
return NO;
}
return YES;
}

创建表:

-(BOOL)createTable:(NSString*)sqlCreateTable  
{
if (![self openOrCreateDatabase:self.m_dbName]) {
return NO;
}
char *errorMsg;
if (sqlite3_exec (self.m_sql, [sqlCreateTable UTF8String],NULL, NULL, &errorMsg) !=
SQLITE_OK)
{
NSLog(@"创建数据表失败:%s",errorMsg);
return NO;
}
[self closeDatabase];
return YES;
}

关闭数据库:

-(void)closeDatabase  
{
sqlite3_close(self.m_sql);
}

//insert

-(BOOL)InsertTable:(NSString*)sqlInsert
{
if (![self openOrCreateDatabase:self.m_dbName]) {
return NO;
}
char* errorMsg = NULL;
if(sqlite3_exec(self.m_sql, [sqlInsert UTF8String],0, NULL, &errorMsg) ==SQLITE_OK)
{ [self closeDatabase];
return YES;}
else {
printf("更新表失败:%s",errorMsg);
[self closeDatabase];
return NO;
}
return YES;
}

更新表格:

-(BOOL)UpdataTable:(NSString*)sqlUpdata{  
if (![self openOrCreateDatabase:self.m_dbName]) {
return NO;
}
char *errorMsg;
if (sqlite3_exec (self.m_sql, [sqlUpdata UTF8String],0, NULL, &errorMsg) !=SQLITE_OK)
{
[self closeDatabase];
return YES;
}else {
return NO;
}

return YES;
}

选择记录:

-(NSArray*)querryTable:(NSString*)sqlQuerry  
{
if (![self openOrCreateDatabase:self.m_dbName]) {
return nil;
}
int row = 0;
int column = 0;
char* errorMsg = NULL;
char** dbResult = NULL;
NSMutableArray* array = [[NSMutableArray alloc] init];
if(sqlite3_get_table(m_sql,[sqlQuerry UTF8String], &dbResult, &row,&column,&errorMsg ) == SQLITE_OK)
{
if (0 == row) {
[self closeDatabase];
return nil;
}
int index = column;
for(int i =0; i < row ; i++ ) {
NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
for(int j =0 ; j < column; j++ ) {
if (dbResult[index]) {
NSString* value = [[NSString alloc] initWithUTF8String:dbResult[index]];
NSString* key = [[NSString alloc] initWithUTF8String:dbResult[j]];
[dic setObject:value forKey:key];
[value release];
[key release];
}
index ++;
}
[array addObject:dic];
[dic release];
}
}else {
printf("%s",errorMsg);
[self closeDatabase];
return nil;
}
[self closeDatabase];
return [array autorelease];
}

最佳答案

您需要将 libsqlite 库添加到链接过程中。这可以在项目设置中完成,参见 https://stackoverflow.com/a/7623043/1091195 .

关于ios - 架构 i386 : "_sqlite3_open", 的 undefined symbol 引用自:错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10412867/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com