This issue has been created to capture discussion that happen in a private email thread.
1) Question from Clement:
How to link dylib files to the ones in a downloaded version of Slicer and not a built version of Slicer?
2) Answer from @jcfr:
(also adding @bpaniagua and @fbudin69500 in cc to keep them in the loop)
To clarify,
(1) linking is a build time process. Since we do not have a Slicer SDK, generally speaking you can not link against library from a downloaded Slcier
(2) resolving symbols. Are you talking about making sure you distributed extension can load in a Slicer installed on MacOSX.
Assuming you talk about (2), you have to make sure that during the building/packaging of your extension, all executables and libraries are properly "fixed up" so that they can find their dependencies and resolve symbols are run time.
When Slicer CLIs are built using the SEMMacroBuildCLI macro, appropriate link flags are associated with the executable.
See https://github.com/Slicer/Slicer/blob/6d1f4bb820d02c86c865517d7524f3641836ccf4/SuperBuild/External_SlicerExecutionModel.cmake#L28-L32
In your particular case, since you are building the "Launcher" executable yourself and that executable lives in the same directory has the other CLIs, I think you have to have explicitly associated these flags.
Based on how the macro is using these flags, maybe something like this will work for you:
set_target_properties(Launcher PROPERTIES LINK_FLAGS ${SlicerExecutionModel_DEFAULT_CLI_EXECUTABLE_LINK_FLAGS})
A few pointer to Clement since he is just starting on this project and probably wondering why things were done like this:
-
There is a launcher because it is not possible to start a QApplication within a QApplication. Slicer is a QApplication, and ShapePopulationViewer is also a QAppication. The launcher creates a "buffer" that allows to run ShapePopulationViewer from within Slicer.
-
The launcher does not use the SEMMacroBuildCLI probably (not sure anymore) because the macro looks for files with a very specific names. There might be different possible workarounds, like @jcfr's solution, to solve that issues.
Clement, how did you install ShapePopulationViewer in Slicer? Did you add manually the path containing the compiled executable of ShapePopulationViewer to your module path, or did you manually install the packaged ShapePopulationViewer extension from the extension manager?
The executable that has to correct paths to find the libraries at runtime is the one created (and fixed up) by the packaging process, so make sure to test that one. One thing you can do to verify that the executable contains the correct information is to print the information it contains to find the libraries it tries to find. On MacOS, you can use the tool named "otool" [1]. Make sure that the paths to the libraries are relative paths, and not absolute, and the "rpath" is set appropriately. I let you do your own research on what rpath is if you don't know ;)
Hope this helps,
Francois
[1] http://stackoverflow.com/questions/12521802/print-rpath-of-executable-on-osx
5) Answer from Clement:
@fbudin69500 : I packaged ShapePopulationViewer, took the ShapePopulationViewer folder from the package, paste the folder into an Extensions-25586
folder equivalent and add the path to the extension into Slicer.
The libraries not found were QtGui, QtCore and QtWidget but were indicated without @rpath
, so I used install_name_tool to change it to @rpath/Frameworks/QtCore.framework/Versions/4/QtGui
as it is in a downloaded version Slicer.
Then, no problem with Libraries but with Symbols not found:
Reading at this quickly I have 2 things to say:
-
Instead of copying ShapePopulationViewer from the package and changing the module path, just manually install the package, it is easier: When you open the extension manager, you have a little wrench icon. If you click on it, it gives you the options to install the extension from file (your zip file).
-
The fix-up step when creating the package should normally take care of this rpath problem.
-
I don't know why it doesn't find your symbol :)
7) Answer from Clement:
I know about installing a package, I previously did it for an other extension I have developed but for ShapePopulationViewer there is an error installing the package:
So, I just used the second option I had to just move the files.
What is the fix-up step you are talking about ?
I am not sure why the install fails for ShapePopulationViewer but works for another extension.
The fix-up step changes the path to the libraries that the software is looking for to work from within Slicer.
This is the short version. @jcfr might be able to give a better explanation.