You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the document says that -DSQLITE_HAS_CODEC need to be set manually in the Other C Flags. It looks like the compilation success without this flag. What issue should I notice in this case?
You'll need the SQLITE_HAS_CODEC flag in your consuming project to enable SQLCipher encryption.
For Objective-C based projects, you'll want to use the Other C Flag -DSQLITE_HAS_CODEC.
For Swift based projects, you'll want to use the SQLITE_HAS_CODEC=1 Preprocessor Macro.
If you don't set the appropriate build setting based on your target language, you should get a compilation failure when attempting to use sqlite3_key along the lines of:
Cannot find 'sqlite3_key' in scope
and SQLCipher encryption won't be enabled.
The README Build Settings section of this project mentions these two different settings depending on your project's language.
In the documentation page you linked from our website, it's not as clear that you'll only need to set the appropriate build setting based on target language (for Swift Package Manager integration). We'll adjust that to make it clearer.
I didn't get any compilation failure when leaving Other C flag empty, any reason?
Are you calling sqlite3_key somewhere in your project's code to key your database? The compilation error will only occur when your project attempts to use sqlite3_key without the appropriate (SQLITE_HAS_CODEC) build setting based on your target language.
If your project's target language is Swift, you'll only need to set the Preprocessor Macro SQLITE_HAS_CODEC=1 for both debug and release as mentioned in my previous comment.
The SQLITE_HAS_CODEC flag (-DSQLITE_HAS_CODEC for Objective-C SQLITE_HAS_CODEC=1 Preprocessor Macro for Swift) needs to the applied to the consuming application's project to enable SQLCipher encryption and utilize functions like sqlite3_key/sqlite3_key_v2 to encrypt databases. There's no capability for Swift Packages to apply CFlags/Preprocessor macros to consuming projects.
Defining SQLITE_HAS_CODEC within the Package.swift would only allow sources within the package to utilize SQLCipher encryption (i.e. call sqlite3_key), but not external sources/consumers.
The same thing would be true if SQLCipher.swift Package contained the source amalgamation rather than a binaryTarget.
I'm trying to use this package in a Cordova plugin (Objective-C), when using cordova-ios 8 with CocoaPods, the dependency SQLCipher works without having to add SQLITE_HAS_CODEC to the app (because the podspec already includes it).
Call to undeclared function 'sqlite3_key'; ISO C99 and later do not support implicit function declarations
I've tried adding SQLITE_HAS_CODEC and/or -DSQLITE_HAS_CODEC to the app and even to my plugin's Package.swift but the code won't compile.
If I add https://github.com/sqlcipher/SQLCipher.swift as a dependency to a project and the source code is also on the project, the same source code compiles when I add SQLITE_HAS_CODEC, but has no effect when the source code is in a swift package (as it is when you are using it in a Cordova or Capacitor plugin)
I'm trying to use this package in a Cordova plugin (Objective-C), when using cordova-ios 8 with CocoaPods, the dependency SQLCipher works without having to add SQLITE_HAS_CODEC to the app (because the podspec already includes it).
With Cocoapods the podspec definition allowed you to define Other C flags for the consuming project. If you pod install with the SQLCipher pod, notice that the -DSQLITE_HAS_CODEC Other C flag is added to your consuming project.
I've tried adding SQLITE_HAS_CODEC and/or -DSQLITE_HAS_CODEC to the app and even to my plugin's Package.swift but the code won't compile.
You'll need to add the SQLITE_HAS_CODEC flag to the location where you're attempting to use SQLCipher encryption. If you have a Swift Package that consumes SQLCipher.swift package (and uses it's encryption), you'll need to add the flag to that package.
For example if you have SQLCipherConsumingPackage which has a dependency on SQLCipher.swift and you intend to use SQLCipher encryption in the code of SQLCipherConsumingPackage, you'll need to add the applicable flag to SQLCipherConsumingPackage Package.swift. Here's an example of what the application portion of the Package.swift might look like:
Then your final consuming project (the app project which is consuming SQLCipherConsumingPackage), can call through to functions in sources internal to SQLCipherConsumingPackage to perform any SQLCipher encryption. If you also need to use sqlite3_key directly in your conusming application (outside of the SQLCipherConsumingPackage), you'll also need to set the applicable SQLITE_HAS_CODEC flag there as well.
But using https://github.com/skiptools/swift-sqlcipher repository, which has the SQLITE_HAS_CODEC in their Package.swift makes my code compile, so that's why I think you should add the SQLITE_HAS_CODEC to the repository's Package.swift.
These are the flags used when compiling sqlite3.c within the package. The binary target within SQLCipher.swift package already includes the SQLITE_HAS_CODEC flag when compiling the binaryTarget, so this isn't the reason why that package works without the undefined function error.
I had already tried adding the cSettings for SQLITE_HAS_CODEC in several different ways ("SQLITE_HAS_CODEC", to: nil), ("SQLITE_HAS_CODEC"), ("SQLITE_HAS_CODEC", to: "1"), and none worked.
The SQLCipher commercial Cordova plugin doesn't currently have a Swift Package associated with it. That being said, we could look into supporting that if you're interested in licensing it. Please reach out to us at support@zetetic.net.
Activity
R4N commentedon Nov 24, 2025
Hi @b95505017
Thanks for your interest in
SQLCipher.swift.You'll need the
SQLITE_HAS_CODECflag in your consuming project to enable SQLCipher encryption.For Objective-C based projects, you'll want to use the Other C Flag
-DSQLITE_HAS_CODEC.For Swift based projects, you'll want to use the
SQLITE_HAS_CODEC=1Preprocessor Macro.If you don't set the appropriate build setting based on your target language, you should get a compilation failure when attempting to use
sqlite3_keyalong the lines of:and SQLCipher encryption won't be enabled.
The README Build Settings section of this project mentions these two different settings depending on your project's language.
In the documentation page you linked from our website, it's not as clear that you'll only need to set the appropriate build setting based on target language (for Swift Package Manager integration). We'll adjust that to make it clearer.
It's good to test and verify that SQLCipher is properly linked/integrated/enabled. We have recommendations at the bottom of the documentation page you linked: https://www.zetetic.net/sqlcipher/sqlcipher-apple-community/#testing-and-verification
b95505017 commentedon Nov 24, 2025
I didn't get any compilation failure when leaving Other C flag empty, any reason?
R4N commentedon Nov 24, 2025
@b95505017
Are you calling
sqlite3_keysomewhere in your project's code to key your database? The compilation error will only occur when your project attempts to usesqlite3_keywithout the appropriate (SQLITE_HAS_CODEC) build setting based on your target language.If your project's target language is Swift, you'll only need to set the Preprocessor Macro
SQLITE_HAS_CODEC=1for both debug and release as mentioned in my previous comment.jcesarmobile commentedon Apr 14, 2026
Couldn't you add the flag in the
Package.swiftusingcSettings? or that doesn't work on binary targets?R4N commentedon Apr 15, 2026
The
SQLITE_HAS_CODECflag (-DSQLITE_HAS_CODECfor Objective-CSQLITE_HAS_CODEC=1Preprocessor Macro for Swift) needs to the applied to the consuming application's project to enable SQLCipher encryption and utilize functions likesqlite3_key/sqlite3_key_v2to encrypt databases. There's no capability for Swift Packages to apply CFlags/Preprocessor macros to consuming projects.Defining
SQLITE_HAS_CODECwithin the Package.swift would only allow sources within the package to utilize SQLCipher encryption (i.e. callsqlite3_key), but not external sources/consumers.The same thing would be true if SQLCipher.swift Package contained the source amalgamation rather than a binaryTarget.
jcesarmobile commentedon Apr 17, 2026
I'm trying to use this package in a Cordova plugin (Objective-C), when using cordova-ios 8 with CocoaPods, the dependency
SQLCipherworks without having to addSQLITE_HAS_CODECto the app (because the podspec already includes it).Trying to update the plugin to use SPM with this repository (https://github.com/sqlcipher/SQLCipher.swift), I get this on this line
sqlite3_key(db, key, strlen(key));But using https://github.com/skiptools/swift-sqlcipher repository, which has the
SQLITE_HAS_CODECin their Package.swift makes my code compile, so that's why I think you should add theSQLITE_HAS_CODECto the repository's Package.swift.If I add
https://github.com/sqlcipher/SQLCipher.swiftas a dependency to a project and the source code is also on the project, the same source code compiles when I addSQLITE_HAS_CODEC, but has no effect when the source code is in a swift package (as it is when you are using it in a Cordova or Capacitor plugin)R4N commentedon Apr 22, 2026
@jcesarmobile
With Cocoapods the podspec definition allowed you to define Other C flags for the consuming project. If you pod install with the SQLCipher pod, notice that the -DSQLITE_HAS_CODEC Other C flag is added to your consuming project.
We sell a SQLCipher for Cordova turnkey solution under our Enterprise program: https://www.zetetic.net/sqlcipher/cordova/ -- you can request a trial of it here: https://www.zetetic.net/sqlcipher/trial/
You'll need to add the SQLITE_HAS_CODEC flag to the location where you're attempting to use SQLCipher encryption. If you have a Swift Package that consumes SQLCipher.swift package (and uses it's encryption), you'll need to add the flag to that package.
For example if you have SQLCipherConsumingPackage which has a dependency on SQLCipher.swift and you intend to use SQLCipher encryption in the code of SQLCipherConsumingPackage, you'll need to add the applicable flag to SQLCipherConsumingPackage Package.swift. Here's an example of what the application portion of the Package.swift might look like:
Then your final consuming project (the app project which is consuming SQLCipherConsumingPackage), can call through to functions in sources internal to SQLCipherConsumingPackage to perform any SQLCipher encryption. If you also need to use sqlite3_key directly in your conusming application (outside of the SQLCipherConsumingPackage), you'll also need to set the applicable SQLITE_HAS_CODEC flag there as well.
These are the flags used when compiling sqlite3.c within the package. The binary target within SQLCipher.swift package already includes the
SQLITE_HAS_CODECflag when compiling the binaryTarget, so this isn't the reason why that package works without the undefined function error.Instead, the https://github.com/skiptools/swift-sqlcipher package you referenced has explicitly commented out the
#ifdef SQLITE_HAS_CODECguard in the sqlite3.h header around sqlite3_key*: https://github.com/skiptools/swift-sqlcipher/blob/main/Sources/SQLCipher/sqlite/sqlite3.h#L6664 so the sqlite3_key function will always be defined even if you're not properly setting SQLITE_HAS_CODEC.jcesarmobile commentedon Apr 22, 2026
I had already tried adding the
cSettingsforSQLITE_HAS_CODECin several different ways("SQLITE_HAS_CODEC", to: nil),("SQLITE_HAS_CODEC"),("SQLITE_HAS_CODEC", to: "1"), and none worked.Does your cordova plugin support SPM?
R4N commentedon Apr 28, 2026
The SQLCipher commercial Cordova plugin doesn't currently have a Swift Package associated with it. That being said, we could look into supporting that if you're interested in licensing it. Please reach out to us at support@zetetic.net.