failed to find protobuf header file

1.6k views Asked by At

I pod Protobuf-C++ in my ios app, but build failed, build error log looks like this

- 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

anyone knonw how to fix this ? my protobuf version is 3.11.3

3

There are 3 answers

2
Rome On

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

maybe other file not found. the way to fix it:

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'
0
allen On

It works for meļ¼Œthanks a lot! @Rome i also checked podspec file of Protofbuf, it has missed this config but others does "xcconfig": { "HEADER_SEARCH_PATHS": "$(PODS_ROOT)/SQLCipher", ...... } which looks like same to your solution

0
ch271828n On

@Rome's solution is quite helpful, but after a pod install, I have to do the same thing again manually. So I try to improve it and with this solution, no extra work is needed.

Put the following code in your 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

In addition, if you have some C++ code that uses protobuf (i.e. includes it), you may also need to do the following in your xxx.podspec:

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