title: iPhone: sqlite db open is not working
body: <p>I am new to iOS sqlite. I am working on xcode 4.2. Here is my code:</p>
  
  <p>.h file</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &lt;/usr/include/sqlite3.h&gt;
  
  @interface RpTestViewController : UIViewController {
      sqlite3 *db;
      NSString *dbPath;
  }
  
  @end
  </code></pre>
  
  <p>.m file</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
  
  
      NSString *docsDir;
      NSArray *dirPaths;
  
      dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      docsDir = [dirPaths objectAtIndex:0];
  
      dbPath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"test.db"]];
  
      NSFileManager *fileMgr = [NSFileManager defaultManager];
  
      if([fileMgr fileExistsAtPath: dbPath] == NO)
      {
          const char *_dbPath = [dbPath UTF8String];
          if(sqlite3_open(_dbPath, &amp;db)  == SQLITE_OK)
          {
              char *err;
              const char *sql = "create table if not exists test_group (groupID integer primary key autoincrement, name, name_arr)";
              if(sqlite3_exec(db, sql, NULL, NULL, &amp;err) != SQLITE_OK)
              {
                  NSLog(@"failed to create table");
              }
              else
              {
                  NSLog(@"ok...");
              }
          }
      }
  }
  </code></pre>
  
  <p>But, i got following error when I try to run:</p>
  
  <pre><code>Ld /Users/remoteprogrammer/Library/Developer/Xcode/DerivedData/fitest-bjghexnpsekbougtezdjshnnugzl/Build/Products/Debug-iphonesimulator/fitest.app/fitest normal i386
      cd /MRK/iPhone/test/fitest
      setenv MACOSX_DEPLOYMENT_TARGET 10.6
      setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
      /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -L/Users/remoteprogrammer/Library/Developer/Xcode/DerivedData/fitest-bjghexnpsekbougtezdjshnnugzl/Build/Products/Debug-iphonesimulator -F/Users/remoteprogrammer/Library/Developer/Xcode/DerivedData/fitest-bjghexnpsekbougtezdjshnnugzl/Build/Products/Debug-iphonesimulator -filelist /Users/remoteprogrammer/Library/Developer/Xcode/DerivedData/fitest-bjghexnpsekbougtezdjshnnugzl/Build/Intermediates/fitest.build/Debug-iphonesimulator/fitest.build/Objects-normal/i386/fitest.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=50000 -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/remoteprogrammer/Library/Developer/Xcode/DerivedData/fitest-bjghexnpsekbougtezdjshnnugzl/Build/Products/Debug-iphonesimulator/fitest.app/fitest
  
  Undefined symbols for architecture i386:
    "_sqlite3_open", referenced from:
        -[RpTestViewController viewDidLoad] in RpTestViewController.o
    "_sqlite3_exec", referenced from:
        -[RpTestViewController viewDidLoad] in RpTestViewController.o
  ld: symbol(s) not found for architecture i386
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>How to resolve this problem.</p>