ios – i386的未定义符号:“_sqlite3_open”,引用来自:error

前端之家收集整理的这篇文章主要介绍了ios – i386的未定义符号:“_sqlite3_open”,引用来自:error前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经创建了一个数据库类并打包了一些方法.但是,一旦建立项目…
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,&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],&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],&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相关文章