# \[Build Error\] \[CentOS 7\] undefined reference to pthread\_\*

**URL:** <https://discourse.slicer.org/t/build-error-centos-7-undefined-reference-to-pthread/15142>\
**Category:** Support\
**Created:** [December 19, 2020, 4:51am UTC](https://discourse.slicer.org/t/build-error-centos-7-undefined-reference-to-pthread/15142 "2020-12-19T04:51:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbillah](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tbillah/32/4139_2.png) [@tbillah](https://discourse.slicer.org/u/tbillah)\
**Post date:** [December 19, 2020, 4:51am UTC](https://discourse.slicer.org/t/build-error-centos-7-undefined-reference-to-pthread/15142/1 "2020-12-19T04:51:11Z")

</div>

Hi,

VTK builds independently in my CentOS 7 machine but appears not to as part of Slicer:

Console log:

```auto
[50%] Building CXX object Interaction/Widgets/CMakeFiles/vtkInteractionWidgetsObjects.dir/vtkContourLineInterpolator.cxx.o
[50%] Linking CXX executable ../../bin/vtkProbeOpenGLVersion
../../lib/libvtkexodusII-8.2.so.1: error: undefined reference to 'pthread_setspecific'
../../lib/libvtkexodusII-8.2.so.1: error: undefined reference to 'pthread_getspecific'
../../lib/libvtkexodusII-8.2.so.1: error: undefined reference to 'pthread_key_create'
../../lib/libvtkexodusII-8.2.so.1: error: undefined reference to 'pthread_mutexattr_settype'
../../lib/libvtkexodusII-8.2.so.1: error: undefined reference to 'pthread_mutexattr_init'
../../lib/libvtkexodusII-8.2.so.1: error: undefined reference to 'pthread_once'
../../lib/libvtkhdf5-8.2.so.1: error: undefined reference to 'dlerror'
../../lib/libvtkhdf5-8.2.so.1: error: undefined reference to 'dlopen'
../../lib/libvtkhdf5-8.2.so.1: error: undefined reference to 'dlsym'
../../lib/libvtkhdf5-8.2.so.1: error: undefined reference to 'dlclose'
collect2: error: ld returned 1 exit status
make[5]: *** [bin/vtkProbeOpenGLVersion] Error 1
make[4]: *** [Rendering/OpenGL2/CMakeFiles/vtkProbeOpenGLVersion.dir/all] Error 2
make[4]: *** Waiting for unfinished jobs....
[50%] Building CXX object Interaction/Widgets/CMakeFiles/vtkInteractionWidgetsObjects.dir/vtkContourWidget.cxx.o
...
...
[57%] Building CXX object Wrapping/Python/CMakeFiles/vtkCommonKitPythonD.dir/vtkCommonKitPythonInitImpl.cxx.o
[57%] Linking CXX shared library ../../lib/libvtkCommonKitPython36D-8.2.so
[57%] Built target vtkCommonKitPythonD
make[3]: *** [all] Error 2
make[2]: *** [VTK-prefix/src/VTK-stamp/VTK-build] Error 2
make[1]: *** [CMakeFiles/VTK.dir/all] Error 2
make: *** [all] Error 2

```

CMakeError.log:

```auto
Run Build Command(s):/usr/bin/gmake cmTC_f23cb/fast
gmake[3]: Entering directory `/data/pnl/soft/pnlpipe3/Slicer-4.11/build/VTK-build/ThirdParty/libxml2/vtklibxml2/CMakeFiles/CMakeTmp'
/usr/bin/gmake -f CMakeFiles/cmTC_f23cb.dir/build.make CMakeFiles/cmTC_f23cb.dir/build
gmake[4]: Entering directory `/data/pnl/soft/pnlpipe3/Slicer-4.11/build/VTK-build/ThirdParty/libxml2/vtklibxml2/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_f23cb.dir/platformTestsC.c.o
/apps/software-compiled/GCCcore/7.3.0/bin/cc -DTEST_HAVE_SYS_NDIR_H -w -w -o CMakeFiles/cmTC_f23cb.dir/platformTestsC.c.o -c /data/pnl/soft/pnlpipe3/Slicer-4.11/build/VTK/ThirdParty/libxml2/vtklibxml2/platformTestsC.c
/data/pnl/soft/pnlpipe3/Slicer-4.11/build/VTK/ThirdParty/libxml2/vtklibxml2/platformTestsC.c:82:10: fatal error: sys/ndir.h: No such file or directory
 #include <sys/ndir.h>
          ^ ~~~~~~~~~~~
compilation terminated.
gmake[4]: *** [CMakeFiles/cmTC_f23cb.dir/platformTestsC.c.o] Error 1
gmake[4]: Leaving directory `/data/pnl/soft/pnlpipe3/Slicer-4.11/build/VTK-build/ThirdParty/libxml2/vtklibxml2/CMakeFiles/CMakeTmp'
gmake[3]: *** [cmTC_f23cb/fast] Error 2
gmake[3]: Leaving directory `/data/pnl/soft/pnlpipe3/Slicer-4.11/build/VTK-build/ThirdParty/libxml2/vtklibxml2/CMakeFiles/CMakeTmp'

```

I have cmake 3.14.2, gcc 7.3.0, and Mesa/18.1.1-foss-2018b. I am trying to build the default configuration with my own `Qt5_DIR`. Do the above errors look familiar? Any tip is appreciated.

---

<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:** [December 20, 2020, 7:49pm UTC](https://discourse.slicer.org/t/build-error-centos-7-undefined-reference-to-pthread/15142/2 "2020-12-20T19:49:11Z")

</div>

Probably the default vtk build doesn’t enable features that lead to the build issue. You can try enabling the same [features that the superbuild does](https://github.com/Slicer/Slicer/blob/master/SuperBuild/External_VTK.cmake) and isolate what leads to the error. If you can reproduce it at the VTK level you can try reporting on their discourse.

---

<div class="post-metadata">

**Author:** ![shangguan](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@shangguan](https://discourse.slicer.org/u/shangguan)\
**Post date:** [December 10, 2021, 3:00am UTC](https://discourse.slicer.org/t/build-error-centos-7-undefined-reference-to-pthread/15142/3 "2021-12-10T03:00:33Z")

</div>

I have same errors. And I tried to add pthread and dl in vtk-cmakelists, but the errors still exists.Have you solve them?really appreciate for your help.

---

<div class="post-metadata">

**Author:** ![shangguan](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@shangguan](https://discourse.slicer.org/u/shangguan)\
**Post date:** [December 14, 2021, 2:36am UTC](https://discourse.slicer.org/t/build-error-centos-7-undefined-reference-to-pthread/15142/4 "2021-12-14T02:36:00Z")

</div>

I’ve fixed the bugs by modify the CmakeLists in /build/VTK.

---

<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:** [December 14, 2021, 5:25am UTC](https://discourse.slicer.org/t/build-error-centos-7-undefined-reference-to-pthread/15142/5 "2021-12-14T05:25:42Z")

</div>

Could you describe the changes that solved the issue for you? Just in case someone else runs into the same problem.

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [December 14, 2021, 9:34am UTC](https://discourse.slicer.org/t/build-error-centos-7-undefined-reference-to-pthread/15142/6 "2021-12-14T09:34:14Z")

</div>

I have ran the same issues when preparin the docker image for Gate.I solved in the moment with

```auto
RUN if ["$Centos_Version" = "centos:7"]; then \
     yum install -y devtoolset-7-gcc-c++ \
  fi

```

But Centos7 proves to be very non friendly with modern packages.So I must move to Centos8 and that’s the current base for [dockerized Gate](https://github.com/OpenGATE/Gate/pull/414)

---

<div class="post-metadata">

**Author:** ![shangguan](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@shangguan](https://discourse.slicer.org/u/shangguan)\
**Post date:** [December 16, 2021, 8:53am UTC](https://discourse.slicer.org/t/build-error-centos-7-undefined-reference-to-pthread/15142/7 "2021-12-16T08:53:34Z")

</div>

Add  
set(CMAKE\_CXX\_FLAGS “${CMAKE\_CXX\_FLAGS} -pthread”)  
set(CMAKE\_CXX\_FLAGS “${CMAKE\_CXX\_FLAGS} -ldl”)  
after project(VTK) in build/VTK/CmakeLists.txt could solve the issues in my ubuntu20 machine.
