zkmkarlsruhe / ofxTensorFlow2

TensorFlow 2 AI/ML library wrapper for openFrameworks
Other
113 stars 17 forks source link

error: Library not loaded: "@rpath/libtensorflow.2.dylib' #38

Closed stephanschulz closed 3 months ago

stephanschulz commented 7 months ago

I am on macOS 12.6.8 with Xcode 141.0. and OF 12 I had this issue. I did add the needed line "$OF_PATH"/addons/ofxTensorFlow2/scripts/macos_install_libs.sh "$TARGET_BUILD_DIR/$PRODUCT_NAME.app"; to the 2nd run script but it did not work.

Screen Shot 2024-02-15 at 6 56 36 PM

I had to add a new run script field by clicking on the + Screen Shot 2024-02-15 at 7 25 40 PM and then add the line as required.

roymacdonald also suggested this option:

in the addons addon_config.mk file

add the following to the osx section

ADDON_LIBS  = libs/tensorflow/lib/osx/libtensorflow_framework.2.8.0.dylib
    ADDON_LIBS  += libs/tensorflow/lib/osx/libtensorflow_framework.2.dylib
    ADDON_LIBS  += libs/tensorflow/lib/osx/libtensorflow_framework.dylib
    ADDON_LIBS  += libs/tensorflow/lib/osx/libtensorflow.2.8.0.dylib
    ADDON_LIBS  += libs/tensorflow/lib/osx/libtensorflow.2.dylib
    ADDON_LIBS  += libs/tensorflow/lib/osx/libtensorflow.dylib
    ADDON_LDFLAGS = -Xlinker -rpath -Xlinker @executable_path

make sure there is a tab at the begining of each line

danomatika commented 7 months ago

I am aware. I looked into updating the scripting for OF 0.12 in Nov but did not have the time to go into it. If anyone has suggestions, that could be helpful.

suyashcjoshi commented 7 months ago

I'm stuck at the same step, it's wasn't even clear which is the '2nd script' being referenced in the README instructions.

danomatika commented 7 months ago

There were multiple custom build scripts for OF 0.11, hence "second script." In OF 0.12 there is only one, I believe, however we have not updated the readme or the script handling yet. I have simply not had the time. If anyone wants to try adapting the current script and/or adding the libs into the .mk file via something like a Make wildcard or glob, feel free.

suyashcjoshi commented 7 months ago

There were multiple custom build scripts for OF 0.11, hence "second script." In OF 0.12 there is only one, I believe, however we have not updated the readme or the script handling yet. I have simply not had the time. If anyone wants to try adapting the current script and/or adding the libs into the .mk file via something like a Make wildcard or glob, feel free.

I can try but might need your help. I'll post my progress here and hope we can update and fix this error so more people can use this awesome addon. I'm happy to write a tutorial about it later as well.

danomatika commented 3 months ago

This should now be fixed in the develop branch.

The main issue was 1. OF 0.12 changed the 2nd Run Script phase when building the project and 2. Xcode somehow now doesn't like the quote usage we had for calling the script.

I've updated the readme with the correct line to copy paste and the configure_xcode.sh script should also work again.

However, this brings in a new issue: Command CodeSign failed with a nonzero exit code when signing the libtensorflow*.dylibs. Basically, this is now happening earlier in the build process before we can install and configure the paths, so you have to remove them from the Copy Files Build Phase. This is easy to do in the UI.

The new process is basically: 1. make sure to add calling the macos_install_libs.sh script and 2. remove the dylibs copy files list:

Screenshot 2024-06-14 at 2 45 17 PM

I think we could probably tell the PG to ignore adding the dylibs to the project directly to avoid this issue. I can look at that next week.

...in the meantime, I can also confirm building libtensorflow for macOS is not too hard, just takes a while. I managed to build example_yolo_v4 with the latest libtensorflow 2.16.1 from the Github sources. 😄

danomatika commented 3 months ago

in the addons addon_config.mk file

add the following to the osx section

ADDON_LIBS  = libs/tensorflow/lib/osx/libtensorflow_framework.2.8.0.dylib
  ADDON_LIBS  += libs/tensorflow/lib/osx/libtensorflow_framework.2.dylib
  ADDON_LIBS  += libs/tensorflow/lib/osx/libtensorflow_framework.dylib
  ADDON_LIBS  += libs/tensorflow/lib/osx/libtensorflow.2.8.0.dylib
  ADDON_LIBS  += libs/tensorflow/lib/osx/libtensorflow.2.dylib
  ADDON_LIBS  += libs/tensorflow/lib/osx/libtensorflow.dylib
  ADDON_LDFLAGS = -Xlinker -rpath -Xlinker @executable_path

Note that this would not work. We have to manually configure the @rpaths inside the libs for them to be loadable within the .app bundle. The macos_install_libs.sh script does this, so it's important to call it, not just add the dylibs when building.

danomatika commented 3 months ago

I'm stuck at the same step, it's wasn't even clear which is the '2nd script' being referenced in the README instructions.

2nd Run Script. Under the Project target's Build Phases, there are two Run Script sections. We need to call the macos_install_script.sh in the 2nd of these.

danomatika commented 3 months ago

This process if fixed with ofxTF2 1.5.0 for OF 0.12. The steps to configure the project are the same as before.