【问题标题】:Xcode 8 symbol not found linking sqlite3找不到链接 sqlite3 的 Xcode 8 符号
【发布时间】:2016-10-03 14:41:24
【问题描述】:

我有一个项目,我使用 2 个 Pod,一个使用 SQLCipher 的私有 Pod,以及使用系统 sqlite3 (-l"sqlite3") 的 Google/Analytics。

当我使用 Xcode 7 构建我的项目时,一切正常,但是当我使用 Xcode 8 构建时,应用程序在尝试打开 sqlite db 时崩溃,原因如下:

dlopen(/usr/lib/libsqlite3.dylib, 0x00000001)
dlopen(/usr/lib/libsqlite3.dylib) ==> 0x1feec4f0
dyld: lazy symbol binding failed: Symbol not found: _sqlite3_key
Referenced from: /var/containers/Bundle/Application/524A1D1F-CC6A-4F7C-B86F-CC65EAF17BD5/MyApp.app/MyApp
Expected in: /usr/lib/libsqlite3.dylib

测试:

|         | iOS 8 | iOS 9 | iOS 10 |
| Xcode 7 |  OK   |  OK   |   OK   |
| Xcode 8 | CRASH | CRASH |    *   |

* app didn't crash but could not open db

Xcode 8 改变了什么? (https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Introduction.html)
有关如何解决此问题的任何建议?

【问题讨论】:

  • This question 似乎表明sqlite3_key() 不包含在 iOS 版本的 sqlite3 中。你也可以关闭这个库的延迟加载吗?
  • @Droppy 你会如何建议我关闭延迟加载?
  • @Daniel 我也遇到了类似的问题,能否请您提出您的解决方案!
  • @Droppy sqlite3_key() 以前使用 X-code 7 和 iOS-9。升级到 X-code 8 和 iOS-10 后,这开始产生问题。你有什么建议!!
  • @Daniel 您对此问题有什么解决方案吗?我也面临同样的问题。

标签: xcode google-analytics sqlite cocoapods sqlcipher


【解决方案1】:

如果使用pod import,可以添加post_install修改OTHER_LDFLAGS,去掉iOS系统sqlite3链接标志l"sqlite3"。

post_install 做 |installer|

installer.pods_project.targets.each do |target|
    puts "#{target.name}"    
    target.build_configurations.each do |config|
        xcconfig_path = config.base_configuration_reference.real_path
        puts xcconfig_path

        build_settings = Hash[*File.read(xcconfig_path).lines.map{|x| x.split(/\s*=\s*/, 2)}.flatten]

        if build_settings['OTHER_LDFLAGS']
            other_ldflags = build_settings['OTHER_LDFLAGS']

            puts other_ldflags

            if other_ldflags.include? '-l"sqlite3"'

                puts "find -l sqlite3"

                index = other_ldflags.index('-l"sqlite3"')
                length = '-l"sqlite3"'.length
                first_path = other_ldflags[0,index]
                last_path = other_ldflags[index+length..-1]
                exclude_ldflags = first_path + last_path

                puts exclude_ldflags

                build_settings['OTHER_LDFLAGS'] = exclude_ldflags
            end

            # write build_settings dictionary to xcconfig
            File.open(xcconfig_path, "w")
            build_settings.each do |key,value|
                File.open(xcconfig_path, "a") {|file| file.puts "#{key} = #{value}"}
            end
        end
    end
end

结束

块引用

【讨论】:

    【解决方案2】:

    不幸的是,同时使用依赖于 sqlite3 和 SQLCipher 的 Pod 并不是 SQLCipher 真正支持的场景。您可以查看这篇文章,其中包含使用 SQLCipher with XCode 8 的指导以供参考,但您尝试做的是高风险。

    【讨论】:

    • 斯蒂芬,我正面临here提到的类似问题,任何建议我做错了什么。
    • 您链接到的帖子中的问题是每次打开数据库时都必须调用 PRAGMA key= 或 sqlite3_key。
    【解决方案3】:

    我正在使用 sqlCipher,我也遇到了这个问题dyld: lazy symbol binding failed: Symbol not found: _sqlite3_key。我所做的是将-all_load 标志添加到项目Build Settings -> Other Linker Flags,然后一切正常。希望这可能对某人有所帮助。 :)

    【讨论】:

      猜你喜欢
      • 2017-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-16
      • 1970-01-01
      • 2011-04-11
      • 2012-06-22
      • 2015-06-27
      相关资源
      最近更新 更多