# Link to module library (not logic, mrml, widgets)

**URL:** <https://discourse.slicer.org/t/link-to-module-library-not-logic-mrml-widgets/4291>\
**Category:** Development\
**Tags:** build\
**Created:** [October 4, 2018, 11:15pm UTC](https://discourse.slicer.org/t/link-to-module-library-not-logic-mrml-widgets/4291 "2018-10-04T23:15:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamrankin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamrankin/32/155_2.png) [@adamrankin](https://discourse.slicer.org/u/adamrankin)\
**Post date:** [October 4, 2018, 11:15pm UTC](https://discourse.slicer.org/t/link-to-module-library-not-logic-mrml-widgets/4291/1 "2018-10-04T23:15:01Z")

</div>

Hello all,

Has anyone linked to a module library? I am trying to call a function in the public interface of the module class, and when I have

```auto
...
set(MODULE_TARGET_LIBRARIES
  vtkSlicer${MODULE_NAME}ModuleLogic
  qSlicerVirtualRealityModuleWidgets
  qSlicerVirtualRealityModule
  )
...

```

the `qSlicerVirtualRealityModule` target does not exist.

So, has anyone done something like this?

Cheers,  
Adam

---

<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:** [October 5, 2018, 3:30am UTC](https://discourse.slicer.org/t/link-to-module-library-not-logic-mrml-widgets/4291/2 "2018-10-05T03:30:49Z")

</div>

Targets listed in `Slicer_TARGETS` CMake variable are exported to the targets file [here](https://github.com/Slicer/Slicer/blob/a335e39f30bdd75b7af7dd2b5b58b0ef68104e76/CMake/SlicerExtensionGenerateConfig.cmake#L114-L115). Each library is added to `Slicer_TARGETS`, for example Qt libraries are added [here](https://github.com/Slicer/Slicer/blob/a335e39f30bdd75b7af7dd2b5b58b0ef68104e76/CMake/SlicerMacroBuildModuleQtLibrary.cmake#L237). Try to find out why module library target is not exported: is it not included in `Slicer_TARGETS`, or there are no exported symbols, …?

---

<div class="post-metadata">

**Author:** ![adamrankin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamrankin/32/155_2.png) [@adamrankin](https://discourse.slicer.org/u/adamrankin)\
**Post date:** [October 5, 2018, 5:06pm UTC](https://discourse.slicer.org/t/link-to-module-library-not-logic-mrml-widgets/4291/3 "2018-10-05T17:06:47Z")

</div>

The library is exported (.lib file exists).

Adding the .lib file manually to the linker inputs results in a successful compile (dumpbin also shows symbol exists in exports).

Target does not exist in CMake, investigating CMake system now.

---

<div class="post-metadata">

**Author:** ![adamrankin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamrankin/32/155_2.png) [@adamrankin](https://discourse.slicer.org/u/adamrankin)\
**Post date:** [October 5, 2018, 6:13pm UTC](https://discourse.slicer.org/t/link-to-module-library-not-logic-mrml-widgets/4291/4 "2018-10-05T18:13:49Z")

</div>

The following line exists in the Qt module macro

```auto
set_property(GLOBAL APPEND PROPERTY Slicer_TARGETS ${MODULEQTLIBRARY_NAME})

```

but is not present in the loadable module CMake.

Presumably this means it is not exported by design? Could it be exported?

Update: I have added the export line to the macro, and the target is included in the XYZTargets.cmake file (as expected).

Edit: compilation fails however, as it most likely has PRIVATE interface\_libraries that should be public?

```auto
Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK1181	cannot open input file 'qSlicerBaseQTCLI.lib'	vtkSlicerVideoPassthroughModuleLogic	C:\d\Slcr\SARR\VideoPassthrough\Logic\LINK	1	
Error	LNK1181	cannot open input file 'qSlicerBaseQTApp.lib'	qSlicerVideoPassthroughModule	C:\d\Slcr\SARR\VideoPassthrough\LINK	1	
Error	LNK1181	cannot open input file 'vtkAddonPythonD.lib'	vtkSlicerVideoPassthroughModuleLogicPythonD	C:\d\Slcr\SARR\VideoPassthrough\Logic\LINK	1	
Error	LNK1181	cannot open input file 'qSlicerBaseQTCLI.lib'	vtkSlicerVideoPassthroughModuleLogicPython	C:\d\Slcr\SARR\VideoPassthrough\Logic\LINK	1	
Error	LNK1181	cannot open input file 'vtkSlicerCamerasModuleLogic.lib'	qSlicerVideoPassthroughModuleGenericCxxTests	C:\d\Slcr\SARR\VideoPassthrough\LINK	1	

```

---

<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:** [October 5, 2018, 6:18pm UTC](https://discourse.slicer.org/t/link-to-module-library-not-logic-mrml-widgets/4291/5 "2018-10-05T18:18:30Z")

</div>

I think it could make sense to make Qt module class (derived from qSlicerLoadableModule) available for other modules. Some features that require Qt and not related to the module widget are implemented in the module class and may be needed to be accessed from other modules.

@jcfr what do you think?

---

<div class="post-metadata">

**Author:** ![adamrankin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamrankin/32/155_2.png) [@adamrankin](https://discourse.slicer.org/u/adamrankin)\
**Post date:** [October 5, 2018, 7:21pm UTC](https://discourse.slicer.org/t/link-to-module-library-not-logic-mrml-widgets/4291/6 "2018-10-05T19:21:40Z")

</div>

Talked to @jcfr, he suggested not to expose the module to protect the design decision of MRML/logic/widget reusability.

I will use a workaround to get the view via Qt methods (find by children by name/class) as the VR subsystem is a “special” snowflake.

---

<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:** [October 5, 2018, 7:26pm UTC](https://discourse.slicer.org/t/link-to-module-library-not-logic-mrml-widgets/4291/7 "2018-10-05T19:26:28Z")

</div>

SlicerVirtualReality is not the only extension that uses module class for module-specific functions that may be useful for other modules. For example, Sequence Browser module uses the module class, too (for managing sequence browser toolbar). Any other logic that requires Qt but it should be available regardless of a module widget must live in the module class.

I agree that it is better if we don’t need to expose the module class, but only if we don’t need uglier workarounds to achieve what we need.
