# Build fails in VTK : many undefined references

**URL:** <https://discourse.slicer.org/t/build-fails-in-vtk-many-undefined-references/12150>\
**Category:** Support\
**Created:** [June 22, 2020, 9:26am UTC](https://discourse.slicer.org/t/build-fails-in-vtk-many-undefined-references/12150 "2020-06-22T09:26:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [June 22, 2020, 9:26am UTC](https://discourse.slicer.org/t/build-fails-in-vtk-many-undefined-references/12150/1 "2020-06-22T09:26:56Z")

</div>

Hello,

Sorry to bother you again. Slicer (128fb86dd18) build fails in VTK on Arch Linux as such :

> /usr/bin/ld: CMakeFiles/vtkProbeOpenGLVersion.dir/vtkProbeOpenGLVersion.cxx.o: in function `main': vtkProbeOpenGLVersion.cxx:(.text.startup+0x25): undefined reference to `vtkRenderer::New()’  
> /usr/bin/ld: vtkProbeOpenGLVersion.cxx:(.text.startup+0x2d): undefined reference to `vtkRenderWindow::New()' /usr/bin/ld: vtkProbeOpenGLVersion.cxx:(.text.startup+0x68): undefined reference to `vtkObjectBase::GetClassName() const’  
> /usr/bin/ld: vtkProbeOpenGLVersion.cxx:(.text.startup+0x172): undefined reference to `vtkOutputWindow::GetInstance()' /usr/bin/ld: vtkProbeOpenGLVersion.cxx:(.text.startup+0x183): undefined reference to `vtkOutputWindow::GetInstance()’  
> … many other undefined references

It’s configured as follows :

> export LANG=C  
> export LC\_ALL=C  
> export CFLAGS=“-I/usr/include/tirpc”  
> export CXXFLAGS=“-I/usr/include/tirpc”  
> cmake -DSlicer\_VTK\_VERSION\_MAJOR:INT=8 -DQt5\_DIR:PATH=/usr/lib/cmake/Qt5 -DBUILD\_TESTING:BOOL=OFF -DCMAKE\_BUILD\_TYPE:STRING=Release -DADDITIONAL\_CXX\_FLAGS:STRING=-I/usr/include/tirpc …/Slicer

I suppose libvtkCommon is not found during linking.

Reporting it in hope of a fix.

Regards.

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [June 22, 2020, 5:43pm UTC](https://discourse.slicer.org/t/build-fails-in-vtk-many-undefined-references/12150/2 "2020-06-22T17:43:17Z")

</div>

Built with clang 10.0 successfully at 76a41991e.

With commit 128fb86dd, there were linking errors as below :

> /usr/bin/ld: …/…/…/bin/libRemoteIO.so: undefined reference to `libssh2_init' /usr/bin/ld: ../../../bin/libRemoteIO.so: undefined reference to `libssh2\_knownhost\_free’  
> /usr/bin/ld: …/…/…/bin/libRemoteIO.so: undefined reference to `libssh2_knownhost_get' /usr/bin/ld: ../../../bin/libRemoteIO.so: undefined reference to `libssh2\_sftp\_open\_ex’  
> /usr/bin/ld: …/…/…/bin/libRemoteIO.so: undefined reference to `libssh2_channel_wait_eof' /usr/bin/ld: ../../../bin/libRemoteIO.so: undefined reference to `libssh2\_session\_method\_pref’  
> /usr/bin/ld: …/…/…/bin/libRemoteIO.so: undefined reference to `libssh2_channel_wait_closed' /usr/bin/ld: ../../../bin/libRemoteIO.so: undefined reference to `libssh2\_agent\_init’  
> /usr/bin/ld: …/…/…/bin/libRemoteIO.so: undefined reference to `libssh2_agent_list_identities' /usr/bin/ld: ../../../bin/libRemoteIO.so: undefined reference to `libssh2\_agent\_connect’  
> /usr/bin/ld: …/…/…/bin/libRemoteIO.so: undefined reference to `libssh2_channel_send_eof' /usr/bin/ld: ../../../bin/libRemoteIO.so: undefined reference to `libssh2\_userauth\_keyboard\_interactive\_ex’  
> /usr/bin/ld: …/…/…/bin/libRemoteIO.so: undefined reference to `libssh2_agent_disconnect' /usr/bin/ld: ../../../bin/libRemoteIO.so: undefined reference to `libssh2\_scp\_recv2’  
> /usr/bin/ld: …/…/…/bin/libRemoteIO.so: undefined reference to `libssh2\_hostkey\_hash’

With gcc 10.1, on top of VTK linking errors, numpy didn’t build, i.e, no \*.so file was found.

Will continue with clang then.

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [June 28, 2020, 11:29am UTC](https://discourse.slicer.org/t/build-fails-in-vtk-many-undefined-references/12150/3 "2020-06-28T11:29:02Z")

</div>

It turns out that the root cause is with the pull request I submitted [recently](https://github.com/Slicer/VTK/pull/28). The ‘tags’ entry should not have been modified. It is set back to the previous value of ‘vtk-old’ in this [corrective](https://github.com/Slicer/VTK/pull/29) pull request.

This allows VTK to compile in a clean build, both with gcc 10.1 and clang 10.0. Moreover, no numpy errors are encountered.

However, this patch was necessary, to allow RemoteIO to link to ssh2.

```
diff --git a/Libs/RemoteIO/CMakeLists.txt b/Libs/RemoteIO/CMakeLists.txt
index 65bd1b6183..23ca01b092 100644
--- a/Libs/RemoteIO/CMakeLists.txt
+++ b/Libs/RemoteIO/CMakeLists.txt
@@ -95,6 +95,7 @@ add_library(${lib_name} ${srcs})
 set(libs
   ${CURL_LIBRARIES}
   MRMLCore
+ ssh2
   )
 if(Slicer_USE_PYTHONQT_WITH_OPENSSL)
   list(APPEND libs

```

I hope the [corrective](https://github.com/Slicer/VTK/pull/29) request is merged in the Slicer/VTK tree.

---

<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 28, 2020, 2:19pm UTC](https://discourse.slicer.org/t/build-fails-in-vtk-many-undefined-references/12150/4 "2020-06-28T14:19:36Z")

</div>

Thank you very much for working on this. We can merge the Slicer/VTK pull request if you touch it up a bit based on [comments](https://github.com/Slicer/VTK/pull/29#issuecomment-650766976). After that, please submit a pull request to Slicer/Slicer that uses the new Slicer/VTK hash and includes all other proposed changes (RemoteIO and anything else that you find necessary).

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [June 28, 2020, 4:16pm UTC](https://discourse.slicer.org/t/build-fails-in-vtk-many-undefined-references/12150/5 "2020-06-28T16:16:33Z")

</div>

I [amended](https://github.com/Slicer/VTK/commit/54838c2ac8f5f8521d4aa1d24988fb9ed1c715b4) the last comment on the fork to be more explicit, and did a forced push. But I am not being able to create a new pull request; no command is available for this, and I am logged in.

> [@lassoan](#):
>
> please submit a pull request to Slicer/Slicer that uses the new Slicer/VTK hash and includes all other proposed changes (RemoteIO…

My first ever pull request has not been a success, so I’m somehow hesitant now.

---

<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 28, 2020, 7:02pm UTC](https://discourse.slicer.org/t/build-fails-in-vtk-many-undefined-references/12150/6 "2020-06-28T19:02:24Z")

</div>

No need to create a new pull request, it is enough to change the content of the branch that the pull request was created for.

Maybe you forgot to rebase your branch on the latest version of the target branch.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [June 28, 2020, 9:44pm UTC](https://discourse.slicer.org/t/build-fails-in-vtk-many-undefined-references/12150/7 "2020-06-28T21:44:10Z")

</div>

> [@chir.set](#):
>
> It turns out that the root cause is with the pull request I submitted [recently](https://github.com/Slicer/VTK/pull/28). The ‘tags’ entry should not have been modified. It is set back to the previous value of ‘vtk-old’ in this [corrective](https://github.com/Slicer/VTK/pull/29) pull request.

Update to `update.sh` associated with commit [Slicer/VTK@b4a1815](https://github.com/Slicer/VTK/commit/b4a181566f8510103333d32d19a567cd5a455a34) (added to branch [slicer-v8.2.0-2018-10-02-74d9488523](https://github.com/Slicer/VTK/commits/slicer-v8.2.0-2018-10-02-74d9488523)) is unlikely to be the source of the problem.

Indeed, we are not running this script while building VTK or Slicer.

I suggest we spend a little bit more time understanding the root cause of the problem. Since we do not call function like `libssh2_agent_disconnect` in Slicer code, adding a dependency to `ssh2` does not seem to be the “right” fix.

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [June 29, 2020, 6:24am UTC](https://discourse.slicer.org/t/build-fails-in-vtk-many-undefined-references/12150/8 "2020-06-29T06:24:29Z")

</div>

Well these are observational findings, perhaps related to Arch’s specifics, being so called ‘bleeding edge’ by nature.

I report these findings in case it’s known to you and a fix can be pointed to, or in case these findings might be useful in the future. I am well aware your build infrastructure is quite different and well described in your factory pages. I am not an IT pro, and won’t ever have such knowledge to venture in advanced tasks like a new pull request.

So in all, I’ll maintain locally a few tweaks that allow me to build Slicer.

As for the ssh2 issue, the new curl pulled in has much to do with ssh2 :

```
LANG=C LC_ALL=C readelf -hs src/Slicer-SuperBuild/curl-build/lib/libcurl.a |grep ssh 
    30: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND Curl_ssh_init
    35: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND Curl_ssh_cleanup
     9: 0000000000000000 80 OBJECT LOCAL DEFAULT 4 ssh_buffer.0
    24: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND Curl_ssh_version
File: src/Slicer-SuperBuild/curl-build/lib/libcurl.a(libssh.c.o)
     1: 0000000000000000 0 FILE LOCAL DEFAULT ABS libssh.c
File: src/Slicer-SuperBuild/curl-build/lib/libcurl.a(libssh2.c.o)
     1: 0000000000000000 0 FILE LOCAL DEFAULT ABS libssh2.c
     5: 0000000000000000 9 FUNC LOCAL DEFAULT 1 my_libssh2_malloc
     6: 0000000000000010 9 FUNC LOCAL DEFAULT 1 my_libssh2_realloc
     7: 0000000000000020 17 FUNC LOCAL DEFAULT 1 my_libssh2_free

```

… …

May be I don’t interpret it rightly. I may of course give you more information you may need.

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [July 7, 2020, 4:35pm UTC](https://discourse.slicer.org/t/build-fails-in-vtk-many-undefined-references/12150/9 "2020-07-07T16:35:53Z")

</div>

Is there an update on this? I have the same problem building on MacOS 10.15.5 (undefined libssh references).

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [July 10, 2020, 5:25pm UTC](https://discourse.slicer.org/t/build-fails-in-vtk-many-undefined-references/12150/10 "2020-07-10T17:25:19Z")

</div>

Does anyone have a workaround to get MacOS builds going? I’ve installed libssh2, but I seem to be unable to tell CMake where to find it. I’ve added the ssh2 library line for RemoteIO (I realize this may be sub-optimal), but make is unable to find libssh2 in /usr/local - I checked link.txt and it does not have -L/usr/local/lib (where libssh2 is located). I’ve tried to add -L/usr/local/lib to what look like CMake LD flag settings, but make still doesn’t look in /usr/local/lib.

How do I add /usr/local/lib to the linker flags for RemoteIO?

Thanks!!

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [July 15, 2020, 1:27pm UTC](https://discourse.slicer.org/t/build-fails-in-vtk-many-undefined-references/12150/11 "2020-07-15T13:27:42Z")

</div>

OK, I think I figured this out. ssh2 is required for RemoteIO, but just adding ssh2 to CMakeLists.txt wasn’t sufficient for my setup - it didn’t know where to find libssh2.dylib. To tell it to get ssh2 from /usr/local (version 1.9.0\_1 installed via HomeBrew), I had to add a call to find\_library() and tell it to look in /usr/local/lib.

```
diff --git a/Libs/RemoteIO/CMakeLists.txt b/Libs/RemoteIO/CMakeLists.txt
index 65bd1b618..a11163e9c 100644
--- a/Libs/RemoteIO/CMakeLists.txt
+++ b/Libs/RemoteIO/CMakeLists.txt
@@ -92,9 +92,12 @@ set(srcs ${RemoteIO_SRCS})

 add_library(${lib_name} ${srcs})

+find_library(SSH2_LIBRARY NAMES ssh2 PATHS /usr/local/lib)
+
 set(libs
   ${CURL_LIBRARIES}
   MRMLCore
+ ${SSH2_LIBRARY}
   )
 if(Slicer_USE_PYTHONQT_WITH_OPENSSL)
   list(APPEND libs

```

Now, I have no idea if this is the _right_ solution, as @jcfr mentioned above. But at least it got the build going.

Any comments?

Thanks!

-Hollister

---

<div class="post-metadata">

**Author:** ![RafaelPalomar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafaelpalomar/32/1436_2.png) [@RafaelPalomar](https://discourse.slicer.org/u/RafaelPalomar)\
**Post date:** [September 29, 2020, 6:51pm UTC](https://discourse.slicer.org/t/build-fails-in-vtk-many-undefined-references/12150/12 "2020-09-29T18:51:16Z")

</div>

Hello,

I left a PR in here: [https://github.com/Slicer/Slicer/pull/5209](https://github.com/Slicer/Slicer/pull/5209). My solution is to disable libssh and libssh2 in curl; as pointed out by @jcfr, these are not used by Slicer.

I hope this is an ok solution.

Best,  
Rafael.
