首页 > 解决方案 > Xcode 构建错误 - “函数 'sqlite3_key' 的隐式声明在 C99 中无效”

问题描述

我正在将一个大型 iOS 应用程序模块化,比如说,MyAppWithDatabase分成两个模块(即项目)。因此,我将一个主项目MyApp作为主机,并将一个链接MyDataPlatform作为同一工作区下的框架MyApp.xcworkspace。当为目标集成SQLCipher pod时它工作正常,但由于所有与数据库相关的代码都在重构MyAppWithDatabase中被移入框架,我只想为框架集成 pod,以保持内部加密机制与主机应用程序的抽象。现在,当我为框架集成时,它开始产生以下构建错误。MyDataPlatformSQLCipher

函数“sqlite3_key”的隐式声明在 C99 中无效

请注意,此问题是由MyApps 源代码的一条语句产生的,作为警告,但 Xcode 构建将其视为错误,

sqlite3_key(_db, [password UTF8String], (int)password.length);

我仍然保留上述行,MyApp因为将数据库相关代码逐渐移入需要时间,MyDataPlatform并且我假设 SQLCipher 标头仍然应该在主机应用程序中可用,作为链接中的相关框架。

我在互联网上浏览了许多提出的解决方案,但没有一个适合我的情况。我怀疑大多数解决方案只是关于集成SQLCipher主机应用程序。在我的情况下,当我收到框架错误时该怎么办?

下面是我的 pod 文件的结构(重构后),

# Uncomment this line to define a global platform for your project
platform :ios, '9.0'

workspace 'MyApp.xcworkspace'

target 'MyApp' do
  # Uncomment this line if you're using Swift or would like to use dynamic frameworks
  use_frameworks!

  pod 'Google/Analytics'
  pod 'GoogleMaps'
  # ...

  target 'MyAppTests' do
    inherit! :search_paths
  end

end

target 'MyDataPlatform' do
  project 'MyDataPlatform/MyDataPlatform.xcodeproj'
  pod 'SQLCipher', '~>3.4.2'

  #https://discuss.zetetic.net/t/ios-11-xcode-issue-implicit-declaration-of-function-sqlite3-key-is-invalid-in-c99/2198/53
  post_install do | installer |
    print "SQLCipher: link Pods/Headers/sqlite3.h"
    system "mkdir -p Pods/Headers/Private && ln -s ../../SQLCipher/sqlite3.h Pods/Headers/Private"
  end
end

之前SQLCipher集成在MyAppWithDatabaseie下

# Uncomment this line to define a global platform for your project
platform :ios, '9.0'

target 'MyAppWithDatabase' do
  # Uncomment this line if you're using Swift or would like to use dynamic frameworks
  use_frameworks!

  pod 'Google/Analytics'
  pod 'GoogleMaps'
  pod 'SQLCipher', '~>3.4.2'
  # ...

  target 'MyAppWithDatabaseTests' do
    inherit! :search_paths
  end

end

标签: iossqlitecompiler-errorscocoapodssqlcipher

解决方案


SQLITE_HAS_CODEC在应用程序中定义后,我的问题得到了解决,

MyApp -> Build Settings -> Other C Flags

SQLITE_HAS_CODEC=1添加应用程序后,另一种解决方案也可以使用,

MyApp -> Build Settings -> Preprocessor Macros

推荐阅读