Using the OpenIGTLink library in a loadable module

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

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

FIND_PACKAGE(OpenIGTLink REQUIRED)

....

target_link_libraries(<yourTargetName> PUBLIC OpenIGTLink)
1 Like

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).