RobertBiehl / caffe2-ios

☕️ Caffe2Kit. A simple one step integration of Caffe2 for iOS.
Apache License 2.0
71 stars 13 forks source link

Header Search Path does not lead to caffe2 headers #1

Closed abjurato closed 7 years ago

abjurato commented 7 years ago

I've tried to install pod as described in repository readme (just adding one string to Podfile), but project fails to get built: screen shot 2017-04-24 at 10 31 31

In build settings i see Header Search Paths:

"$(PODS_TARGET_SRCROOT)/lib/caffe2/install/include/"
"$(PODS_TARGET_SRCROOT)/lib/caffe2/third_party/eigen/"

which is resolved by Xcode8.3.1 as /lib/caffe2/install/include and /lib/caffe2/third_party/eigen, which I obviously don't have.

Neither project hierarchy Pods/Caffe2Kit/lib/caffe2 do have such subfolders:

screen shot 2017-04-24 at 10 28 31

Are not these .h files supposed to be copied together with .a files? Or I've missed something?

RobertBiehl commented 7 years ago

@abjurato I'm investigating. I think it can be solved by changing source_files and private_header_files in the podspec.

RobertBiehl commented 7 years ago

@abjurato can you try again? I added ss.preserve_paths = 'lib/caffe2/install/include/**/*.h', 'lib/caffe2/third_party/eigen/Eigen/*', 'lib/caffe2/LICENSE', 'lib/caffe2/PATENTS' to the podspec. I can't reproduce the error anymore.

(The build time is really stressing me out, I think I'll put precompiled libs into the pod later tonight)

abjurato commented 7 years ago

$(PODS_TARGET_SRCROOT)/lib/xxx is still resolved as /lib/xxx - relatively to root. According to this issue such thing happens from time to time: https://github.com/CocoaPods/CocoaPods/issues/5375

So I've just replaced "$(PODS_TARGET_SRCROOT)/" with "$(PODS_ROOT)/Caffe2Kit/" everywhere in Build Settings of my project and pods project. After that I've started getting linker error:

'/Users/blablabla/neural3/Pods/Caffe2Kit/lib/caffe2/install/lib/libCaffe2_CPU.a(nnpack_ops.cc.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64

So I've switched off bitcode for project and pods. After that I've started getting 190 another linker errors: screen shot 2017-04-24 at 15 19 28

I'm not keen in Build Settings magic, unfortunately, but this some kind of a progress

RobertBiehl commented 7 years ago

@abjurato

Ok, will change that in the Podspec.

To disable bitcode, add this to your Podfile:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end
abjurato commented 7 years ago

What can be done to these 190 linker errors?

RobertBiehl commented 7 years ago

@abjurato Let's try something: can you add libstdc++ to your main project? It should have been included by cocoa pods already. Will need to check that out again. screen shot 2017-04-24 at 15 45 54

abjurato commented 7 years ago

@RobertBiehl yep, that worked! but I don't see it included by cocoapods anywhere

RobertBiehl commented 7 years ago

@abjurato Ok, we'll figure it out. Thanks for testing and helping me find these issues. I'll close this, once I fixed it in the pod.

abjurato commented 7 years ago

@RobertBiehl let me know when everything will be fixed, I'll test once again on new clear project. And thanks for your work!

RobertBiehl commented 7 years ago

@abjurato do you use use_frameworks! in your Podfile?

abjurato commented 7 years ago

@RobertBiehl it is default podfile created by pod init with only one Caffe2Kit pod:

target 'neural3' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for neural3
  pod 'Caffe2Kit', :git => 'git://github.com/RobertBiehl/caffe2-ios', :submodules => true
end
abjurato commented 7 years ago

And after all, if I'll run app (even without importing Caffe2Kit anywhere in app target) on device, it crashes:

[libprotobuf ERROR /Users/anatoly/Library/Caches/CocoaPods/Pods/External/Caffe2Kit/3b111c97bfcd807473b4683067cd82dc/lib/caffe2/third_party/protobuf/src/google/protobuf/descriptor_database.cc:57] File already exists in database: caffe/proto/caffe.proto
[libprotobuf FATAL /Users/anatoly/Library/Caches/CocoaPods/Pods/External/Caffe2Kit/3b111c97bfcd807473b4683067cd82dc/lib/caffe2/third_party/protobuf/src/google/protobuf/descriptor.cc:1272] CHECK failed: generated_database_->Add(encoded_file_descriptor, size): 
libc++abi.dylib: terminating with uncaught exception of type google::protobuf::FatalException: CHECK failed: generated_database_->Add(encoded_file_descriptor, size): 
RobertBiehl commented 7 years ago

Wow, I encountered all of these things, but I thought I fixed them. It works for me at least. Back to the drawing board.

Sent from my iPad

On 24. Apr 2017, at 22:06, Anatoly Rosencrantz notifications@github.com wrote:

And after all, if I'll run app (even without importing Caffe2Kit anywhere in app target) on device, it crashes:

[libprotobuf ERROR /Users/anatoly/Library/Caches/CocoaPods/Pods/External/Caffe2Kit/3b111c97bfcd807473b4683067cd82dc/lib/caffe2/third_party/protobuf/src/google/protobuf/descriptor_database.cc:57] File already exists in database: caffe/proto/caffe.proto [libprotobuf FATAL /Users/anatoly/Library/Caches/CocoaPods/Pods/External/Caffe2Kit/3b111c97bfcd807473b4683067cd82dc/lib/caffe2/third_party/protobuf/src/google/protobuf/descriptor.cc:1272] CHECK failed: generateddatabase->Add(encoded_file_descriptor, size): libc++abi.dylib: terminating with uncaught exception of type google::protobuf::FatalException: CHECK failed: generateddatabase->Add(encoded_file_descriptor, size): — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

RobertBiehl commented 7 years ago

@abjurato This happens when libCaffe2_CPU.a is linked more than once.

RobertBiehl commented 7 years ago

@abjurato I updated the repo. Unfortunately I had to add more installations steps to the README.md Unfortunately I were not able to handle these things inside the pod spec yet.

Additional steps 2) should solve the libprotobuf ERROR.

📲 Installation

Disable Bitcode

Since caffe2 is not yet built with bitcode support you need to add this to your Podfile

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end

and disable bitcode for your Target by setting Build Settings -> Enable Bitcode to No.

Additional steps:

These steps will hopefully be removed in later versions. 1) in Build Phases -> Your Target -> Link Binary with Libraries add libstc++.tdb. 2) in Build Settings -> Other Linker Flags remove $(inherited)and -force_load "$(PODS_ROOT)/Caffe2Kit/install/lib/libCaffe2_CPU.a"

abjurato commented 7 years ago

Latest version works totally correctly, thanks a lot!

Another thought: if not all of caffe2's dependencies are installed (like python2.7, for example), build_ios.sh will fail. Maybe worth mentioning that in overview for people not coming from caffe2 repository?

RobertBiehl commented 7 years ago

@abjurato I now switched over to pre-built binaries. The goal is to make it as simple as possible and for most users not requiring to run build_ios.sh.

abjurato commented 7 years ago

cool, so this issue can be closed. Thanks a lot for your work again!