# Problems with linking GLEW (in MXE build)

**URL:** https://discourse.vtk.org/t/problems-with-linking-glew-in-mxe-build/7522
**Category:** Support
**Created:** [December 29, 2021, 1:42pm UTC](https://discourse.vtk.org/t/problems-with-linking-glew-in-mxe-build/7522 "2021-12-29T13:42:34Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Aziuth](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@Aziuth](https://discourse.vtk.org/u/Aziuth)
#### Post date: [December 29, 2021, 1:42pm UTC](https://discourse.vtk.org/t/problems-with-linking-glew-in-mxe-build/7522/1 "2021-12-29T13:42:34Z")

</div>

I have a (C++) project using VTK (8.2) which I cross-compile to Windows using MXE (with cmake).  
The latter information is relevant since the MXE folder contains all the libraries, including Qt, VTK and GLEW, and has actually built them.

This worked fine for quite a while. Then the build environment was updated (but not the MXE folder, mostly the computer was restarted and general updates were fetched) and since then linking fails with errors for `libvtkRenderingVolumeOpenGL2-8.2` related to GLEW:

```auto
[8%] Linking CXX executable <name>.exe
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):
vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text+0x4299):
undefined reference to ` __imp___ glewGenVertexArrays'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text+0x42ae):
undefined reference to ` __imp___ glewGenBuffers'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text+0x4300):
undefined reference to ` __imp___ glewDeleteVertexArrays'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text+0x4323):
undefined reference to ` __imp___ glewBindBuffer'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text+0x4331):
undefined reference to ` __imp___ glewDeleteBuffers'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text+0x4353):
undefined reference to ` __imp___ glewBindBuffer'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text+0x4361):
undefined reference to ` __imp___ glewDeleteBuffers'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text+0x12cc3):
undefined reference to ` __imp___ glewBindVertexArray'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text+0x12cd0):
undefined reference to ` __imp___ glewBindBuffer'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text+0x12f0d):
undefined reference to ` __imp___ glewBindVertexArray'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text+0x12f1a):
undefined reference to ` __imp___ glewBindBuffer'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text+0x12f2b):
undefined reference to ` __imp___ glewBufferData'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text+0x1300d):
undefined reference to ` __imp___ glewBufferData'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text$_ZN18vtkVolumeStateRAIID1Ev[_ZN18vtkVolumeStateRAIID1Ev]+0x9):
undefined reference to ` __imp___ glewBindVertexArray'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLGPUVolumeRayCastMapper.cxx.obj):vtkOpenGLGPUVolumeRayCastMapper.cxx:(.text$_ZN18vtkVolumeStateRAIID1Ev[_ZN18vtkVolumeStateRAIID1Ev]+0x17):
undefined reference to ` __imp___ glewBindBuffer'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLProjectedTetrahedraMapper.cxx.obj):vtkOpenGLProjectedTetrahedraMapper.cxx:(.text+0x43ea):
undefined reference to ` __imp___ glewDrawRangeElements'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLProjectedTetrahedraMapper.cxx.obj):vtkOpenGLProjectedTetrahedraMapper.cxx:(.text+0x4494):
undefined reference to ` __imp___ glewBlitFramebuffer'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkOpenGLProjectedTetrahedraMapper.cxx.obj):vtkOpenGLProjectedTetrahedraMapper.cxx:(.text+0x48f7):
undefined reference to ` __imp___ glewBlitFramebuffer'
/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libvtkRenderingVolumeOpenGL2-8.2.a(vtkVolumeTexture.cxx.obj):vtkVolumeTexture.cxx:(.text+0x3349):
undefined reference to ` __imp___ glewTexSubImage3D'
collect2: error: ld returned 1 exit status

```

I made sure that libglew32s.a (and the other GLEW library files, just in case) is added to the required libraries in my cmake file:

```auto
target_link_libraries(<name> <other libraries> /var/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libGLEW.a /var/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libglew32.a /var/opt/mxe/usr/x86_64-w64-mingw32.static/lib/libglew32s.a)

```

I took a look into the symbols in libglew32s.a, and what I found was that while ` __glewGenVertexArrays` exists, `__ imp___glewGenVertexArrays` doesn’t.

I originally asked for help on StackOverflow: [c++ - Problems linking GLEW with cmake - Stack Overflow](https://stackoverflow.com/questions/70275668/problems-linking-glew-with-cmake#70275668)  
But it seems that my problem might be too exotic.

From some other questions in here I briefly assumed that it might be a OpenGL version incompatibility, or better to say that GLEW was compiled for OpenGL 1 while VTK 8.2 requires OpenGL 2, but given that MXE is build in one go, it would be kind of strange that some parts of it use different versions than others.

Can anybody help? Should I provide more of my information? (Didn’t want to make my question too big, but can gladly provide my cmake file, for example.)  
Am I in the right place or do you think it is better to seek help in a forum for GLEW?

---

<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: [January 2, 2022, 9:28pm UTC](https://discourse.vtk.org/t/problems-with-linking-glew-in-mxe-build/7522/2 "2022-01-02T21:28:17Z")

</div>

This probably means that the symbols are not exported properly as, IIRC, `__imp` is something related to `declspec(dllexport)`.

---

<div class="post-metadata">

### Author: ![Aziuth](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@Aziuth](https://discourse.vtk.org/u/Aziuth)
#### Post date: [January 3, 2022, 11:14am UTC](https://discourse.vtk.org/t/problems-with-linking-glew-in-mxe-build/7522/3 "2022-01-03T11:14:58Z")

</div>

I’m not quite sure how I’d be to resolve this - recompile GLEW? Recompile VTK?

---

<div class="post-metadata">

### Author: ![Aziuth](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@Aziuth](https://discourse.vtk.org/u/Aziuth)
#### Post date: [January 21, 2022, 1:13pm UTC](https://discourse.vtk.org/t/problems-with-linking-glew-in-mxe-build/7522/4 "2022-01-21T13:13:08Z")

</div>

As a different test, I successfully cross-compiled one of the examples (CylinderExample) using the same libraries.  
I strongly assume that my problem is only in regard to a small selection of functions, mostly in `vtkOpenGLGPUVolumeRayCastMapper` and `vtkOpenGLProjectedTetrahedraMapper`.

---

<div class="post-metadata">

### Author: ![Aziuth](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@Aziuth](https://discourse.vtk.org/u/Aziuth)
#### Post date: [January 21, 2022, 3:15pm UTC](https://discourse.vtk.org/t/problems-with-linking-glew-in-mxe-build/7522/5 "2022-01-21T15:15:50Z")

</div>

Solved my issue by slowly extending CylinderExample to work in Qt and then noticed when the error suddenly appeared.  
The culprit was a line in my code,

```
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);

```

which I thought to be required.  
Removing it fixed my problem.

I have no idea why and would be interested to hear what I did wrong there.
