# CLI linking error

**URL:** <https://discourse.slicer.org/t/cli-linking-error/542>\
**Category:** Development\
**Tags:** build, extensions-manager\
**Created:** [June 20, 2017, 7:19pm UTC](https://discourse.slicer.org/t/cli-linking-error/542 "2017-06-20T19:19:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![prisgdd](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/prisgdd/32/1261_2.png) [@prisgdd](https://discourse.slicer.org/u/prisgdd)\
**Post date:** [June 20, 2017, 7:19pm UTC](https://discourse.slicer.org/t/cli-linking-error/542/1 "2017-06-20T19:19:57Z")

</div>

I am currently trying to package my extension with Qt scripted modules and CLI modules.  
The packaging process is successfull. Then, when I use the CLI, I have the following linking error:

> dyld: Library not loaded: @rpath/lib/Slicer-4.7/libITKFactoryRegistration.dylib  
> Referenced from: /Users/prisgdd/ShapeVariationAnalyzer-build/\_CPack\_Packages/ShapeVariationAnalyzer/lib/Slicer-4.7/hidden-cli-modules/./computemean  
> Reason: image not found  
> Trace/BPT trap: 5

Any suggestion on how to solve that?

Thank you!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 20, 2017, 8:10pm UTC](https://discourse.slicer.org/t/cli-linking-error/542/2 "2017-06-20T20:10:55Z")

</div>

How do you package your extension?  
How do you attempt to run the CLI?  
Does the CLI work in Slicer if you [install the extension from generated extension package file](https://www.slicer.org/wiki/Documentation/Nightly/SlicerApplication/ExtensionsManager#Installing_an_extension_without_network_connection)?

---

<div class="post-metadata">

**Author:** ![prisgdd](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/prisgdd/32/1261_2.png) [@prisgdd](https://discourse.slicer.org/u/prisgdd)\
**Post date:** [June 20, 2017, 8:29pm UTC](https://discourse.slicer.org/t/cli-linking-error/542/3 "2017-06-20T20:29:30Z")

</div>

I have a recently built Slicer on my computer, so I’m building my extension giving Slicer’s directory.  
`cmake -DSlicer_DIR=/path/to/Slicer-SuperBuild/Slicer-build -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_OSX_SYSROOT=<sdkroot> -DCMAKE_OSX_DEPLOYMENT_TARGET=<deploy-target> -DCMAKE_BUILD_TYPE=Release ../ShapeVariationAnalyzer`

Then, I add the path to my extension’s modules (cli and qt scripted) and tried to run the CLI with the button dedicated to do so on my extension but also loading the cli-module in Slicer. Both actions gave the same issue.  
I tried to install the extension from the generated extension package file but it says it can’t copy the source folder to the destination folder and it aborts the process.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 20, 2017, 8:56pm UTC](https://discourse.slicer.org/t/cli-linking-error/542/4 "2017-06-20T20:56:35Z")

</div>

It may be possible that the executables stored in the created extension package only work with an installed Slicer. So, either try running Slicer from the build tree and use binaries of your extension from the build tree; or install Slicer and install your extension from file.  
You can read a bit more about CMake’s RPATH handling [here](https://cmake.org/Wiki/CMake_RPATH_handling).

I don’t use MacOSX, so I cannot give any further help, but @pieper or other Mac users should be able to give more information.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [June 20, 2017, 10:27pm UTC](https://discourse.slicer.org/t/cli-linking-error/542/5 "2017-06-20T22:27:13Z")

</div>

@lassoan may be right about the extension only running from an install try. Did you try making an installed version of your local mac build?

Run `make package` from the Slicer-superbuild/Slicer-build directory and then (eventually) you’ll get an \_CPack\_Packages with an install tree in it. Let us know if you have the same path error.

-Steve

---

<div class="post-metadata">

**Author:** ![prisgdd](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/prisgdd/32/1261_2.png) [@prisgdd](https://discourse.slicer.org/u/prisgdd)\
**Post date:** [June 20, 2017, 10:58pm UTC](https://discourse.slicer.org/t/cli-linking-error/542/6 "2017-06-20T22:58:19Z")

</div>

Thanks for your help!

This is how we initially tried, but the path error is the same…

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 21, 2017, 1:11am UTC](https://discourse.slicer.org/t/cli-linking-error/542/7 "2017-06-21T01:11:27Z")

</div>

Have you been able to successfully install the extension package from file using extension manager in Slicer?

---

<div class="post-metadata">

**Author:** ![prisgdd](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/prisgdd/32/1261_2.png) [@prisgdd](https://discourse.slicer.org/u/prisgdd)\
**Post date:** [June 21, 2017, 3:24pm UTC](https://discourse.slicer.org/t/cli-linking-error/542/8 "2017-06-21T15:24:21Z")

</div>

- When I install the extension from file on a downloaded nightly version, the following error occured:  

- When I use the built Slicer I used to build the extension, Slicer crashes and the extension isn’t installed when I restart it.

I tried with the `make install` command, and I have a lot of that following warning for different libraries:

> –  
> warning: cannot resolve item ‘@rpath/lib/Slicer-4.7/liboflog.8.dylib’

> ## possible problems: need more directories? need to use InstallRequiredSystemLibraries? run in install tree instead of build tree?

Which produces this error:

> – 260/522: copying ‘@rpath/lib/Slicer-4.7/liboflog.8.dylib’  
> Error copying file “@rpath/lib/Slicer-4.7/liboflog.8.dylib” to “/usr/local/Slicer.app/Contents/Extensions-0ef0792/ShapeVariationAnalyzer/lib/Slicer-4.7/liboflog.8.dylib”.

And then:

> – 521/522: fixing up ‘/usr/local/Slicer.app/Contents/Extensions-0ef0792/ShapeVariationAnalyzer/lib/Slicer-4.7/liboflog.8.dylib’  
> warning: target ‘/usr/local/Slicer.app/Contents/Extensions-0ef0792/ShapeVariationAnalyzer/lib/Slicer-4.7/liboflog.8.dylib’ does not exist…  
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/objdump: ‘/usr/local/Slicer.app/Contents/Extensions-0ef0792/ShapeVariationAnalyzer/lib/Slicer-4.7/liboflog.8.dylib’: No such file or directory.  
> fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool: internal objdump command failed  
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/objdump: ‘/usr/local/Slicer.app/Contents/Extensions-0ef0792/ShapeVariationAnalyzer/lib/Slicer-4.7/liboflog.8.dylib’: No such file or directory.  
> fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool: internal objdump command failed  
> error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install\_name\_tool: can’t open file: /usr/local/Slicer.app/Contents/Extensions-0ef0792/ShapeVariationAnalyzer/lib/Slicer-4.7/liboflog.8.dylib (No such file or directory)

---

<div class="post-metadata">

**Author:** ![prisgdd](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/prisgdd/32/1261_2.png) [@prisgdd](https://discourse.slicer.org/u/prisgdd)\
**Post date:** [June 21, 2017, 8:41pm UTC](https://discourse.slicer.org/t/cli-linking-error/542/9 "2017-06-21T20:41:20Z")

</div>

Good news: After cleaning the repository and the different CMakeLists, it works well!

I don’t know what was exactly the problem. We started from the creation of a new extension with the Extension Wizard, to be sure we had the good architecture and set the variables correctly.

Thanks for your suggestion!
