Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation issues for M1 / arm64 #33

Closed
golanlevin opened this issue Oct 1, 2022 · 3 comments
Closed

Compilation issues for M1 / arm64 #33

golanlevin opened this issue Oct 1, 2022 · 3 comments

Comments

@golanlevin
Copy link

golanlevin commented Oct 1, 2022

Hi friends,
I'm having M1-architecture-related linking problems ("Undefined Symbol" etc.) similar to those described in Issues #15 and #3. I have tried the posted fixes without luck, and also (possibly) discovered a problem with one of the scripts. My configuration is:

  • Hardware: MacBook Pro (14-inch, 2021) with Apple M1 Pro.
  • Software: OSX 12.6, XCode 14.0.1 (14A400).
  • Building within a fresh copy of of_v0.11.2_osx_release.

I have followed the posted instructions as follows:

  • I did the downloads: I cloned https://github.com/zkmkarlsruhe/ofxTensorFlow2.git to OFROOT/addons; I pulled & checked-out cppflow to ofxTensorFlow2/libs/cppflow (using git submodule update --init --recursive); and I downloaded the models using ./scripts/download_example_models.sh.
  • I'm pretty certain that I'm using c++14. I updated CLANG_CXX_LANGUAGE_STANDARD = c++14 suchly in CoreOF.xcconfig. I also updated PLATFORM_CXXFLAGS += -std=c++14 suchly at line 142 of config.osx.default.mk.
  • I used download_tensorflow.sh to install libtensorflow.2.8.0 in ofxTensorFlow2/libs/tensorflow/. As expected, these x86_64 libraries didn't work; so, I then replaced the contents of the ofxTensorFlow2/libs/tensorflow/ directory with the "unofficial" arm64 materials from https://github.com/vodianyk/libtensorflow-cpu-darwin-arm64.
  • I created the project example_video_matting.xcodeproj using the Project generator
  • In the Build Phases for this project's target, in the 2nd Run Script, I added the following before the final echo line: $OF_PATH/addons/ofxTensorFlow2/scripts/macos_install_libs.sh "$TARGET_BUILD_DIR/$PRODUCT_NAME.app";
  • As recommended, I set Build Settings->Excluded Architectures to "x86_64" for the Project. (For good measure, I also tried every combination of arm64/x86_64 libraries with excluding each architecture, since there is seemingly contradictory advice about which architectures to exclude here and here)
  • I cleaned the build folder before trying to (re)build.

Unfortunately, I'm still getting Undefined Symbols for all of the Tensorflow stuff:

Screen Shot 2022-10-01 at 3 43 45 AM

I feel like I'm close, but I'm out of ideas for how to get further. Thanks so much for any help.

Side Note 1: The ofxTensorFlow2 script, configure_xcode.sh, appears to be corrupting XCode 14 projects. After I run this script, .xcodeproj files no longer open, and XCode reports the error: "The project ‘example_video_matting’ is damaged and cannot be opened due to a parse error. Examine the project file for invalid edits or unresolved source control conflicts."

Side Note 2: FWIW, TensorFlow.org is now offering version 2.9.1 for download (though, there is no indication that it works for arm64).

@danomatika
Copy link
Member

danomatika commented Oct 1, 2022

For future reference, the issue was caused by the libs not being in a subfolder named for the system / build environment, in this case "osx":

libs/tensorflow/lib/*.dylibs <-- WHY U NO WORK?!
libs/tensorflow/lib/osx/*dylibs <-- WORK

This is a subtle issue that the download script handles for you but easy to miss if doing things manually, especially considering the downloaded library structure is very similar.

I've updated the README to clarify this point (under Dependencies) as well as smoothed over some other workflow details on macOS. The updated info is mainly in this commit: 4e4866e

@golanlevin
Copy link
Author

Thanks, @danomatika, for your incredibly helpful advice. It works like a charm. Having the Zoom-quality body segmentation of ofxTensorflow2 (in arbitrary scenes!), in an open-source arts toolkit like openframeworks is simply astounding. I would have killed for this 20 years ago. Kudos to you, @zkmkarlsruhe, and all the other contributors for making this possible.

Screen Shot 2022-10-01 at 11 11 27 PM

@danomatika
Copy link
Member

danomatika commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants