Error when trying to use the SQLite wrapper FMDatabase
Asked Answered
B

3

10

I'm having trouble when I try to use FMDatabase.

I have added theese files:

FMDatabaseQueue
FMDatabaseAdditions
FMDatabase
FMResultSet
FMDatabasePool

..and I have also added the libsqlite3.dylib library and imported FMDatabase.h, but as soon as I uncomment this line:

FMDatabase *db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];

..I get this error:

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_FMDatabase", referenced from:
      objc-class-ref in DBWrapper.o
ld: symbol(s) not found for architecture i386

I have also tried changing settings like Deployment target between 4.0 - 5.0 and creating a new, clean project, etc.

I'm using Xcode Version 4.3 (4E109).

What am I doing wrong? :)

// Stefan

Blim answered 29/2, 2012 at 15:14 Comment(2)
Have you added .h and .m files to your project?Salba
Yes, I have added all files from src except fmdb.m.Blim
C
17

That's a linker error—meaning, everything you fed the compiler was fine but once it came time to package all the compiled object code together into an executable it couldn't find the implementation for a class that was referenced in the code.

Dragging .m files into the project source list in Xcode should automatically add them to the "build phase", but if you did that and you're getting this error, check that they're in there: Click the top-level item in the left-side source list to get the project settings, click the target in the next pane, click the "Build Phases" column header in the next pane, then expand the "Compile sources" row. If the FM files aren't in there, click the + button at the bottom of the list and select them.

Construe answered 29/2, 2012 at 23:4 Comment(2)
This is bug in Xcode 4.3 btw that makes the "Add to targets" checkbox unchecked when adding files.Sydelle
Keep on rockin', Xcode.. Thanks for the note--I'll be sure to keep an eye out for files dropping out of the build phase.Construe
P
2

Expanding on davehayden's answer...

If you add a folder of header and source files into Xcode, the .m files are not added to the Compile Sources list. I usually get caught out here because I want to retain a sensible folder structure in my project folder. To get around this, I manually copy the files into my project folder where I want them. Then in Xcode, add each individual header and source file to my project without copying (using File > Add Files To...). Select all the loose files in the Project Navigator, right click, and make a folder from selection.

A bit late, but I hope this helps someone else.

Perbunan answered 7/5, 2015 at 15:43 Comment(0)
V
1

Have you imported the FMDB headers in the place that you're using them?

#import "FMDatabase.h"
Visitant answered 29/2, 2012 at 17:54 Comment(1)
Yes. I can define my database variable like this: FMDatabase *db; and it works. It crashes as soon as I uncomment [FMDatabase databaseWithPath:@"/tmp/tmp.db"];.Blim

© 2022 - 2024 — McMap. All rights reserved.