# vtk9 rc1: OSMESA support doesn't compile

**URL:** https://discourse.vtk.org/t/vtk9-rc1-osmesa-support-doesnt-compile/2927
**Category:** Development
**Created:** [March 31, 2020, 3:19pm UTC](https://discourse.vtk.org/t/vtk9-rc1-osmesa-support-doesnt-compile/2927 "2020-03-31T15:19:30Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Marcin\_Krotkiewski](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcin_krotkiewski/32/1534_2.png) [@Marcin\_Krotkiewski](https://discourse.vtk.org/u/Marcin_Krotkiewski)
#### Post date: [March 31, 2020, 3:19pm UTC](https://discourse.vtk.org/t/vtk9-rc1-osmesa-support-doesnt-compile/2927/1 "2020-03-31T15:19:30Z")

</div>

Hi,  
I try to compile vtk 9 rc1 with osmesa support. It seems that although I set the include and library path, those variables are not used by CMake in the build process. I configure as follows:

```auto
OSMESA_INCLUDE_DIR /home/angainor/mesa/install/include
OSMESA_LIBRARY /home/angainor/mesa/install/lib/x86_64-linux-gnu/libOSMesa.so
VTK_OPENGL_HAS_OSMESA = ON

```

When I compile, very early on I get the following error:

```auto
vtk/vtk-release/ThirdParty/glew/vtkglew/src/glew.c:41:12: fatal error: GL/osmesa.h: No such file or directory
   41 | # include <GL/osmesa.h>
      | ^ ~~~~~~~~~~~~

```

When I run `make VERBOSE=1` I do not see the configured OSMESA include dir in the command line. I tried to explicitly add `-I...` to CXX and C flags. That works, but then I experience linker errors and unresolved symbols.

The same works with vtk 8.2. Is this a problem with v9?

Thanks!

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 31, 2020, 3:50pm UTC](https://discourse.vtk.org/t/vtk9-rc1-osmesa-support-doesnt-compile/2927/2 "2020-03-31T15:50:57Z")

</div>

Can you see what the `VTK::opengl` target looks like either by tracing the execution trhough `Utilities/OpenGL/CMakeLists.txt` or checking on what the `VTK::opengl` and `VTK::glew` target properties look like in the `lib/cmake/vtk-9.0/VTK-targets.cmake` file in the build tree?

---

<div class="post-metadata">

### Author: ![Marcin\_Krotkiewski](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcin_krotkiewski/32/1534_2.png) [@Marcin\_Krotkiewski](https://discourse.vtk.org/u/Marcin_Krotkiewski)
#### Post date: [March 31, 2020, 4:34pm UTC](https://discourse.vtk.org/t/vtk9-rc1-osmesa-support-doesnt-compile/2927/3 "2020-03-31T16:34:11Z")

</div>

Thanks, @ben.boeckel. In ` Utilities/OpenGL/CMakeLists.txt` I see this:

```auto
if (VTK_OPENGL_HAS_OSMESA AND NOT VTK_CAN_DO_ONSCREEN)
  vtk_module_third_party_external(
    PACKAGE OSMesa
    TARGETS OSMesa::OSMesa)
else ()
...

```

I don’t know what `VTK_CAN_DO_ONSCREEN` exactly means, but I guess it could be that osmesa is not used if onscreen rendering is available? There is no other mention of `OSMesa` in this file.

In `VTK-targets.cmake` I see this:

```auto
# Create imported target VTK::opengl
add_library(VTK::opengl INTERFACE IMPORTED)
...
set_target_properties(VTK::opengl PROPERTIES
  INTERFACE_LINK_LIBRARIES "OpenGL::OpenGL;OpenGL::GLX"
)
...
set_target_properties(VTK::glew PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/vtk-9.0;${_IMPORT_PREFIX}/include/vtk-9.0/"
  INTERFACE_LINK_LIBRARIES "VTK::opengl"
  INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "include/vtk-9.0/"
)

```

No sign of `OSMesa`.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 31, 2020, 5:09pm UTC](https://discourse.vtk.org/t/vtk9-rc1-osmesa-support-doesnt-compile/2927/4 "2020-03-31T17:09:09Z")

</div>

OK, the logic in `CMake/vtkOpenGLOptions.cmake` is going bad somewhere. If you trace it through, does anything not make sense in your setup? (FWIW, ParaView has OSMesa binaries that are working, but it probably is doing less than what your build is trying.)

---

<div class="post-metadata">

### Author: ![Marcin\_Krotkiewski](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcin_krotkiewski/32/1534_2.png) [@Marcin\_Krotkiewski](https://discourse.vtk.org/u/Marcin_Krotkiewski)
#### Post date: [March 31, 2020, 5:27pm UTC](https://discourse.vtk.org/t/vtk9-rc1-osmesa-support-doesnt-compile/2927/5 "2020-03-31T17:27:57Z")

</div>

> [@ben.boeckel](#):
>
> but it probably is doing less than what your build is trying

Could you have a brief look at my custom config values? I essentially only add Java bindings, the rest is autodetected:

```auto
set(CMAKE_INSTALL_PREFIX "/home/angainor/vtk/VTK-9.0.0.rc1/install" CACHE PATH "")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
set(BUILD_TESTING "OFF" CACHE BOOL "")
set(VTK_RENDERING_BACKEND "OpenGL2" CACHE STRING "")
set(VTK_SMP_IMPLEMENTATION_TYPE "OpenMP" CACHE STRING "")
set(VTK_LEGACY_REMOVE "ON" CACHE BOOL "")
set(VTK_USE_LARGE_DATA "OFF" CACHE BOOL "")
set(VTK_USE_64BIT_IDS "OFF" CACHE BOOL "")
set(VTK_WRAP_JAVA "ON" CACHE BOOL "")
set(VTK_JAVA_INSTALL "ON" CACHE BOOL "")
set(JAVA_AWT_INCLUDE_PATH "/home/angainor/jdk1.8.0_77/include/linux" CACHE PATH "")
set(JAVA_AWT_LIBRARY "/home/angainor/jdk1.8.0_77/jre/lib/amd64/libjawt.so" CACHE FILEPATH "")
set(JAVA_INCLUDE_PATH "/home/angainor/jdk1.8.0_77/include" CACHE PATH "")
set(JAVA_INCLUDE_PATH2 "/home/angainor/jdk1.8.0_77/include/linux" CACHE PATH "")
set(JAVA_JVM_LIBRARY "/home/angainor/jdk1.8.0_77/jre/lib/amd64/server/libjvm.so" CACHE FILEPATH "")
set(Java_JAR_EXECUTABLE "/home/angainor/jdk1.8.0_77/bin/jar" CACHE FILEPATH "")
set(Java_JAVAC_EXECUTABLE "/home/angainor/jdk1.8.0_77/bin/javac" CACHE FILEPATH "")
set(Java_JAVADOC_EXECUTABLE "/home/angainor/jdk1.8.0_77/bin/javadoc" CACHE FILEPATH "")
set(Java_JAVAH_EXECUTABLE "/home/angainor/jdk1.8.0_77/bin/javah" CACHE FILEPATH "")
set(Java_JAVA_EXECUTABLE "/home/angainor/jdk1.8.0_77/bin/java" CACHE FILEPATH "")
set(OSMESA_INCLUDE_DIR "/home/angainor/mesa/install/include" CACHE PATH "")
set(OSMESA_LIBRARY "/home/angainor/mesa/install/lib/x86_64-linux-gnu/libOSMesa.so" CACHE FILEPATH "")
set(VTK_OPENGL_HAS_OSMESA "ON" CACHE BOOL "")

```

Otherwise, `build/CMakeCache.txt` says

```auto
VTK_USE_X:BOOL=ON
VTK_OPENGL_HAS_EGL:BOOL=OFF
VTK_OPENGL_HAS_OSMESA:BOOL=ON
VTK_DEFAULT_RENDER_WINDOW_OFFSCREEN:BOOL=OFF
VTK_DEFAULT_RENDER_WINDOW_HEADLESS:BOOL=OFF

```

So I guess the logic is that I should have the following results:

```auto
VTK_CAN_DO_OFFSCREEN TRUE
VTK_CAN_DO_ONSCREEN TRUE
VTK_CAN_DO_HEADLESS TRUE

```

I don’t see anything unreasonable with those values. Looks all OK.

---

<div class="post-metadata">

### Author: ![Marcin\_Krotkiewski](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcin_krotkiewski/32/1534_2.png) [@Marcin\_Krotkiewski](https://discourse.vtk.org/u/Marcin_Krotkiewski)
#### Post date: [March 31, 2020, 5:34pm UTC](https://discourse.vtk.org/t/vtk9-rc1-osmesa-support-doesnt-compile/2927/6 "2020-03-31T17:34:11Z")

</div>

In the meantime I tried a vanilla configure without any of my options. It seems that I can only set `VTK_OPENGL_HAS_OSMESA`, but the other two options I used from 8.2 are not available in `ccmake` advanced mode (`OSMESA_INCLUDE_DIR` and `OSMESA_LIBRARY`). I only find `OPENGL_xmesa_INCLUDE_DIR OPENGL_xmesa_INCLUDE_DIR-NOTFOUND`.

Am I using some deprecated variables here? Maybe I should provide the mesa installation location differently?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 31, 2020, 5:41pm UTC](https://discourse.vtk.org/t/vtk9-rc1-osmesa-support-doesnt-compile/2927/7 "2020-03-31T17:41:10Z")

</div>

> [@Marcin\_Krotkiewski](#):
>
> `OSMESA_INCLUDE_DIR` and `OSMESA_LIBRARY`

The `VTK_CAN_DO_ONSCREEN` option masks even asking for OSMesa. Something is making that variable not be what is needed. `VTK_USE_X` looks to be it.

@ken-martin We probably need to look at the `vtkOpenGLOptions.cmake` logic again. I probably mixed something up.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 31, 2020, 5:42pm UTC](https://discourse.vtk.org/t/vtk9-rc1-osmesa-support-doesnt-compile/2927/8 "2020-03-31T17:42:35Z")

</div>

Ah, set `VTK_USE_X=OFF`. You can’t use X and OSMesa at the same time (since OSMesa apparently turns off X support) and asking for X takes precedence.

---

<div class="post-metadata">

### Author: ![Marcin\_Krotkiewski](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcin_krotkiewski/32/1534_2.png) [@Marcin\_Krotkiewski](https://discourse.vtk.org/u/Marcin_Krotkiewski)
#### Post date: [March 31, 2020, 5:47pm UTC](https://discourse.vtk.org/t/vtk9-rc1-osmesa-support-doesnt-compile/2927/9 "2020-03-31T17:47:36Z")

</div>

I’ll try that, thanks! but will I then be able to use the same compilation for both headless and on-screen visualization? or do I have to compile a separate installation for off-screen rendering?

Indeed, turning off `VTK_USE_X` gave me the option to set `OSMESA` paths. so I guess this is it.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 31, 2020, 6:15pm UTC](https://discourse.vtk.org/t/vtk9-rc1-osmesa-support-doesnt-compile/2927/10 "2020-03-31T18:15:26Z")

</div>

Currently, on or off screen rendering (with OSMesa at least) is a compile-time option; each VTK only supports one or the other.

---

<div class="post-metadata">

### Author: ![Marcin\_Krotkiewski](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcin_krotkiewski/32/1534_2.png) [@Marcin\_Krotkiewski](https://discourse.vtk.org/u/Marcin_Krotkiewski)
#### Post date: [March 31, 2020, 6:22pm UTC](https://discourse.vtk.org/t/vtk9-rc1-osmesa-support-doesnt-compile/2927/11 "2020-03-31T18:22:31Z")

</div>

OK, thanks a lot, all clear!

---

<div class="post-metadata">

### Author: ![aeslaughter](https://discourse.vtk.org/user_avatar/discourse.vtk.org/aeslaughter/32/2332_2.png) [@aeslaughter](https://discourse.vtk.org/u/aeslaughter)
#### Post date: [March 17, 2021, 11:10pm UTC](https://discourse.vtk.org/t/vtk9-rc1-osmesa-support-doesnt-compile/2927/12 "2021-03-17T23:10:21Z")

</div>

Could you please share your complete cmake setup that allowed you to get this working?
