5

I am trying to add SQLite to my project.I checked the target dependencies under the build phase tab,it is empty, which is true.I am getting the following error:Unable to run command 'Ld SQLite' - this target might include its own product."

I am using swift 3. Can you please help me? Thanks in advance

Ali Riahipour
  • 524
  • 6
  • 20
matlabuser
  • 101
  • 1
  • 11
  • All of the similar errors that I've seen on StackOverflow about "target might include its own product" seem to come down to some weird target configuration problems (the dependencies, non-source included in compile sources, etc.). You might want to save this project folder and create a new project from scratch, adding the relevant sources and see new clean copy of the project manifests the same problem... – Rob Jan 24 '18 at 06:47
  • Are you using any third-party libraries (such as some SQLite wrapper)? If so, which one(s)? – Rob Jan 24 '18 at 16:46

2 Answers2

3

I'm not in front of a Mac at present, but I think all you need to do under Build Phases is go to Link Binaries with Libraries, hit the add button and type in "sqlite" so you can select libsqlite3.

Stonetip
  • 1,150
  • 10
  • 20
3

Xcode 9 and Swift 3.2 (or, obviously Swift 4), just import SQLite3 in your relevant Swift file ...

import SQLite3

... and it will import the library for you.

In older Xcode versions (or if you turned off automatic library/framework linking), you have to manually link to the libsqlite3 library in the target settings under the “Build Phases”:

enter image description here

But in Xcode 9 with the default settings, all you need is that import line.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • still NO such module sqlite3 – matlabuser Jan 23 '18 at 20:12
  • What version of Xcode are you running? I just tested this on Xcode 9.2 and Swift 3.2 and it works fine. – Rob Jan 23 '18 at 20:22
  • In Xcode 8, you can't use this automatic import of `SQLite3` feature. You have to manually add it to your "Link Binary with Libraries" in the "Build Phases" of your target settings as shown in https://stackoverflow.com/a/28642293/1271826. – Rob Jan 23 '18 at 20:55
  • I'm wondering if you also then need the bridging header as in the SO answer @Rob linked to. – Stonetip Jan 24 '18 at 02:47
  • @Stonetip - Yeah, you generally have to do that in earlier versions of Xcode. But then again, his error appears to be in the linker, so he must have compiled successfully to get that far, which means that it couldn't be a bridging header problem. Frankly, though, I'm not sure what to make of his error message, though. The SQLite thing may be a red herring for some other problem. – Rob Jan 24 '18 at 06:36