# Using the OpenIGTLink library in a loadable module

**URL:** <https://discourse.slicer.org/t/using-the-openigtlink-library-in-a-loadable-module/3503>\
**Category:** Development\
**Tags:** build, extensions-manager\
**Created:** [July 17, 2018, 2:26pm UTC](https://discourse.slicer.org/t/using-the-openigtlink-library-in-a-loadable-module/3503 "2018-07-17T14:26:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tiffas](https://avatars.discourse-cdn.com/v4/letter/t/ba9def/32.png) [@Tiffas](https://discourse.slicer.org/u/Tiffas)\
**Post date:** [July 17, 2018, 2:26pm UTC](https://discourse.slicer.org/t/using-the-openigtlink-library-in-a-loadable-module/3503/1 "2018-07-17T14:26:00Z")

</div>

Hi,

I am trying to use the OpenIGTLink library in a C++ module with the following code:

```
igtl::ClientSocket::Pointer socket;
socket = igtl::ClientSocket::New();

int r = socket->ConnectToServer("172.31.1.2", 18944); 

```

I got a linker error at the third line: undefined reference to ’ igtl::ClientSocket::ConnectToServer(char const\*, int, bool) ’

Is there a special command to add to the module CMakeLists so that the linker knows it must search for the OpenIGTLink libraries ? I tried to add set(EXTENSION\_DEPENDS “OpenIGTLink”) in the extension CMakeLists but it did not work.

Many thanks,  
Loïc

---

<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:** [July 17, 2018, 2:43pm UTC](https://discourse.slicer.org/t/using-the-openigtlink-library-in-a-loadable-module/3503/2 "2018-07-17T14:43:37Z")

</div>

In your CMake code, you’ll also need to add

```auto
FIND_PACKAGE(OpenIGTLink REQUIRED)

....

target_link_libraries(<yourTargetName> PUBLIC OpenIGTLink)

```

---

<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:** [July 17, 2018, 3:21pm UTC](https://discourse.slicer.org/t/using-the-openigtlink-library-in-a-loadable-module/3503/3 "2018-07-17T15:21:54Z")

</div>

Typically you don’t need such low-level access to OpenIGTLink library. You just create a connector node in the scene to open a connection and content of messages (transforms, images, models, etc.) are turned into MRML nodes. If you have new custom message types then you only need to define a custom converter, which creates/updates MRML nodes from OpenIGTLink messages (and may also create OpenIGTLink messages from MRML nodes).
