【问题标题】:failed to find protobuf header file找不到 protobuf 头文件
【发布时间】:2021-02-02 21:00:46
【问题描述】:

我在我的 ios 应用中 pod Protobuf-C++,但构建失败,构建错误日志如下所示

- NOTE  | [iOS] xcodebuild:  Protobuf-C++/src/google/protobuf/io/zero_copy_stream.cc:35:10: fatal error: 'google/protobuf/io/zero_copy_stream.h' file not found
- NOTE  | [iOS] xcodebuild:  Protobuf-C++/src/google/protobuf/wrappers.pb.cc:4:10: fatal error: 'google/protobuf/wrappers.pb.h' file not found

有人知道如何解决这个问题吗?我的 protobuf 版本是 3.11.3

【问题讨论】:

    标签: protobuf-c


    【解决方案1】:

    problem like this

    'google/protobuf/any.h' file not found
    'google/protobuf/arena_test_util.h' file not found
    'google/protobuf/util/delimited_message_util.h' file not found
    

    可能没有找到其他文件。 解决方法:

    way to fix

    1. select 'Pods'
    2. select 'Protobuf-C++'
    3. select 'Build Settings'
    4. search 'search path'
    5. select 'Header Search Paths'
    6. add '$(SRCROOT)/Protobuf-C++/src'
    

    【讨论】:

    • 它对我有用,非常感谢! @Rome 我还检查了 Protofbuf 的 podspec 文件,它错过了这个配置,但其他人做了 "xcconfig": { "HEADER_SEARCH_PATHS": "$(PODS_ROOT)/SQLCipher", ...... } 这看起来和你的解决方案一样
    • 嗨,pod install 之后,我必须手动再次执行相同的操作。有没有办法自动做到这一点?谢谢!
    【解决方案2】:

    它对我有用,非常感谢! @罗马 我还检查了 Protofbuf 的 podspec 文件,它错过了这个配置,但其他人做了“xcconfig”: { "HEADER_SEARCH_PATHS": "$(PODS_ROOT)/SQLCipher", …… } 这看起来与您的解决方案相同

    【讨论】:

      【解决方案3】:

      @Rome 的解决方案很有帮助,但是在安装 pod 之后,我必须再次手动执行相同的操作。所以我尝试改进它,使用这个解决方案,不需要额外的工作。

      将以下代码放入您的Podfile

      post_install do |installer|
        installer.pods_project.targets.each do |target|
          # print "target=", target, "\n"
          if target.name == "Protobuf-C++"
            target.build_configurations.each do |config|
              config.build_settings['HEADER_SEARCH_PATHS'] = '$(SRCROOT)/Protobuf-C++/src'
            end
          end
        end
      end
      

      此外,如果您有一些使用 protobuf(即包含它)的 C++ 代码,您可能还需要在 xxx.podspec 中执行以下操作:

        s.pod_target_xcconfig = {
          'HEADER_SEARCH_PATHS' => '$(SRCROOT)/Protobuf-C++/src',
        }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-04-04
        • 1970-01-01
        • 2012-08-27
        • 1970-01-01
        • 1970-01-01
        • 2016-03-31
        • 2015-04-28
        相关资源
        最近更新 更多