Trouble with dylib's

#1

EDIT : (rewriting the question)

I am linking a dylib into an XCode project.
I’m just using the default settings from Project Generator

When the application starts, it crashes out:

I’m wondering what the best way is to get this working?
I’m aiming for the addon to have project generator compatibility

I’ve tried:

  1. Manually copying in the dylib files into a number of locations inside the app package
  2. Adding the dylib files to ‘Embedded Binaries’

I’m not very experienced with oF+XCode recently, so any hints are welcome.

Thank you

#3

I got a little hint from https://www.chilkatsoft.com/chilkatMacOSX.asp

I changed the install name with the command

install_name_tool -id “@loader_path/libceres.2.0.0.dylib” libceres.2.0.0.dylib

and copied the dylib into the Contents/MacOS folder of the application bundle manually. That seems to work. Searching for a cleaner option…

#4

i did the same as elliot by adding a build phase in xcode.

cp $OF_PATH/addons/ofxNDI/libs/libndi/lib/osx/libndi.dylib $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/
cd $TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/
install_name_tool -change @rpath/libndi.3.dylib @executable_path/libndi.3.dylib $PRODUCT_NAME
#5

When you compile a lib for OSX you can set the path for the app to look for the lib, it can be @executable_path, @loader_path, or @rpath. The install name change tool will take care of discrepancies, but if you would prefer a path that is friendly to the project generator you would have to recompile the lib.

Some info: https://wincent.com/wiki/@executable_path,@load_path_and@rpath

#6

Ha. I was dealing with this same thing, although I’ve been looking on how to make this process automagically without need for changing any setting in xcode

If you select the project in the left pane navigator and then go to Build Phases you can add a script as @thomasgeissl describes. In there you’ll find that there are other scripts and in one there is how libfmodex is copied and linked (yeah, this lib it is still being used.!). notice that rsync is used instead of cp to avoid unnecesary spent time copying something that might be already there.

Another option is to have the library installed “globally” on your computer or simply have it in your addons folder and not copying into the app bundle, and not using install_name_tool. For this you need to set the rpath in the Build Settings put the absolute path to the folder that has the libraries
in the Runpath Search Paths field.

I’ll bring some news if I find anything interesting.

cheers

#7

Thanks for the help all!

@thomasgeissl
thanks! is there a way to add such a build phase setting into the project generator?

@fresla
As far as I can tell, the project generator cannot assign any setting to the project which copies the dylib into the app package. Therefore there is no path which is friendly to project generator since the file simply isn’t there (unless you go for absolute paths / system paths, which any built app non-portable).

@roymacdonald
Thanks for the tips. It seems that using the ‘Embedded Binaries’ setting is as good as rsync (so long as you’re happy with the resulting dylib location)

And yes - it was working with global install at first, which isn’t great because it’s non-portable.

I guess for the time being I just need to add something to the readme about copying libs and give up on auto-project generator.

#8

or add this feature to PG. :slight_smile:

It think it would be super useful to be able to specify these post build scripts in it. I’ll take a look and let you know if I make any improvements.
cheers

#9

I thought this was there, but it’s onlu working for windows. I’ve included some missing flags in the template:

ADDON_DLLS_TO_COPY allows to copy dlls from the addon folders to the executable folder or the bundle in the case of osx. I thought there was also an ADDON_AFTER that runs a script after the addon is installed but i think it only works with the makefiles right now.

1 Like
#10

Aha, that is great, I thought it was just my ineptitude that was stopping the PG do this kind of copy for OSX. Hence the tip above for @elliotwoods.

#11

Just a quick and dirty hack for this to work.

Open this addons addon_config.mk file and add the following line

ADDON_LDFLAGS =  -rpath /path/to/your/openFrameworks/folder/addons/ofxWhatever/libs/path/to where/the/dylib/files/are 

by changing where it says /path/to/your/openFrameworks/folder/addons/ofxWhatever/libs/path/to where/the/dylib/files/are for the absolute path to the folder that contains the dylibs. It is important that this is the absolute path.

If you are not sure about the absolute path of this folder, an easy trick is to open the terminal (type terminal on the spotlight search and press enter) and drag and drop the folder with the dylibs into the terminal window that you just opened. There it will show the absolute path to the folder you just dragged, select that text copy and paste into addon_config.mk . :slight_smile:

@arturo ADDON_DLLS_TO_COPY does not seem to work on osx. I’ll take a look at it later.