# VTK\_MODULE\_INIT in 9.0.1 ?

**URL:** https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632
**Category:** Support
**Created:** [April 23, 2021, 9:47pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632 "2021-04-23T21:47:10Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![langer](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@langer](https://discourse.vtk.org/u/langer)
#### Post date: [April 23, 2021, 9:47pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/1 "2021-04-23T21:47:10Z")

</div>

In a C++ program that links to VTK, using VTK 8.2 the library was initialized it with

```
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkRenderingContextOpenGL2);
[etc]

```

Does that still work with 9.0.1? I’m getting compiler errors like

[…]/include/vtk-9.0/vtkAutoInit.h:88:3: error: expected identifier before ‘{’ token

If it matters, for historical reasons my program is not built with cmake.

Thanks,  
Steve

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [April 23, 2021, 11:41pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/2 "2021-04-23T23:41:04Z")

</div>

I’m not completely certain, but I think the basic workings of autoinit are the same for VTK 9. But the dependencies might have been shuffled around a bit.

Before `#include <vtkAutoInit.h>`, you will need definitions like this:

```auto
#define vtkRenderingCore_AUTOINIT 1(vtkRenderingOpenGL2)

```

The documents for autoinit are [here](https://vtk.org/doc/nightly/html/md__builds_gitlab-kitware-sciviz-ci_Documentation_Doxygen_ModuleSystem.html), they’re cmake-centric but they describe some of the inner workings.

Edit: it might be more like this:

```auto
#define vtkRenderingContext2D_AUTOINIT 1(vtkRenderingContextOpenGL2)
#define vtkRenderingCore_AUTOINIT 3(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingOpenGL2)
#define vtkRenderingVolume_AUTOINIT 1(vtkRenderingVolumeOpenGL2)

```

---

<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: [April 24, 2021, 5:44pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/3 "2021-04-24T17:44:31Z")

</div>

Things do compile down to `VTK_MODULE_INIT`, but the interface generated is the code shown above. I think you need to include a header from the module you want to initialize as well, but I’m not sure. I figured it out once to write the new module system’s autoinit support, but it’s way too complicated to stick for long.

---

<div class="post-metadata">

### Author: ![langer](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@langer](https://discourse.vtk.org/u/langer)
#### Post date: [April 26, 2021, 7:12pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/4 "2021-04-26T19:12:32Z")

</div>

I’m afraid I’m not getting much out of the module system documentation. Is there some way to find out which autoinit #defines I need, perhaps from a list of which vtk headers I’m including in my C++ code? Or is there a list of what the options are, so that I can experiment to see which ones eliminate the build errors?

Is it possible to download all of the C++ examples in bulk? I could build them and see what definitions cmake generates for the examples that use the parts of vtk that I need. Would that work?

Thanks,  
Steve

---

<div class="post-metadata">

### Author: ![seanm](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/a88e4f/32.png) [@seanm](https://discourse.vtk.org/u/seanm)
#### Post date: [April 26, 2021, 7:16pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/5 "2021-04-26T19:16:24Z")

</div>

Steve,

Not sure it will help you, but here’s the snippet from my Xcode-based project that uses VTK built by CMake:

```auto
	// VTK factory methods require "auto-initialization".
	// <http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Factories_now_require_defines>
	#include "vtkAutoInit.h"
	#include "vtkRenderingOpenGLConfigure.h"
	VTK_MODULE_INIT(vtkInteractionStyle)
	VTK_MODULE_INIT(vtkRenderingFreeType)
	VTK_MODULE_INIT(vtkRenderingOpenGL2)

```

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [April 26, 2021, 7:30pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/6 "2021-04-26T19:30:45Z")

</div>

Did you try the `#define`s that I suggested? You might have missed them if you’re reading through email, since I edited my response via discourse rather than sending an additional reply.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [April 26, 2021, 7:39pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/7 "2021-04-26T19:39:53Z")

</div>

There is a utility to determine the VTK module dependencies for a source file. You can run

```python
python <vtk-source-directory>/Utilities/Maintenance/FindNeededModules.py \
 -j <vtk-build-directory>/modules.json -s <your source file>

```

Run on the VTK source file `Filters/Modeling/Testing/Cxx/TestRotationalExtrusion.cxx`, it produces

```auto
find_package(VTK
 COMPONENTS
    CommonCore
    FiltersCore
    FiltersModeling
    FiltersSources
    RenderingCore
    TestingCore
    TestingRendering
    # These modules are suggested since they implement an existing module.
    # Uncomment those you need.
    # FiltersParallel # implements VTK::FiltersCore
    # FiltersParallelGeometry # implements VTK::FiltersCore
    # InteractionStyle # implements VTK::RenderingCore
    # RenderingFreeType # implements VTK::RenderingCore
    # RenderingOpenGL2 # implements VTK::RenderingCore
    # RenderingUI # implements VTK::RenderingCore
)

```

While this generates a `find_package` call meant for use in CMake, you can extract the module names listed under COMPONENTS, prepend “vtk” onto them, and you’ve got at least the module dependencies.

---

<div class="post-metadata">

### Author: ![langer](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@langer](https://discourse.vtk.org/u/langer)
#### Post date: [April 27, 2021, 2:39am UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/8 "2021-04-27T02:39:07Z")

</div>

Thanks, David. Adding those lines before vtkAutoInit.h didn’t change anything.

---

<div class="post-metadata">

### Author: ![langer](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@langer](https://discourse.vtk.org/u/langer)
#### Post date: [April 27, 2021, 2:47am UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/9 "2021-04-27T02:47:12Z")

</div>

Cory – this looks like it’s sending me in the right direction. Do I need to use the results to construct the `#define`s that David suggested, somehow? Do the commented out lines give me choices of different implementations, where I’m supposed to pick just one?

I’m sorry if I’m being dim. I feel that there are fundamental topics here that I don’t understand, and haven’t found the right references for.

---

<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: [April 27, 2021, 1:21pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/10 "2021-04-27T13:21:37Z")

</div>

> [@langer](#):
>
> I’m afraid I’m not getting much out of the module system documentation.

Yeah, it’s more focused on how to use its APIs rather than on how its APIs work internally.

> [@langer](#):
>
> Is there some way to find out which autoinit #defines I need, perhaps from a list of which vtk headers I’m including in my C++ code?

Once you have the `WhatModulesVTK.py` output (uncommenting some of the implementation modules if you need them), you can write a small project:

```cmake
cmake_minimum_required(VERSION 3.13)
project(vtktest C CXX)

find_package(VTK) # see WhatModulesVTK.py output
add_library(foo dummy.cxx)
target_link_libraries(foo) # link what VTK libraries you want
vtk_module_autoinit(TARGETS foo MODULES …) # same VTK libraries as above

```

When you generate this project, there’s a header named `vtkModuleAutoInit_<md5hash>.h` in the build tree. This is the set of defines you need.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [April 27, 2021, 2:44pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/11 "2021-04-27T14:44:43Z")

</div>

> [@langer](#):
>
> Do I need to use the results to construct the `#define`s that David suggested, somehow?

Yes, that’s my understanding. I would include all the commented out lines to be safe.

> [@langer](#):
>
> I’m sorry if I’m being dim. I feel that there are fundamental topics here that I don’t understand, and haven’t found the right references for.

It’s a complex system. Usually the advice is to use CMake for the build system as the module system is set up to work with `find_package`.

---

<div class="post-metadata">

### Author: ![langer](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@langer](https://discourse.vtk.org/u/langer)
#### Post date: [April 28, 2021, 1:35am UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/12 "2021-04-28T01:35:16Z")

</div>

What happens when a project wants to use vtk but also links with a library that requires a different build system, other than cmake?

---

<div class="post-metadata">

### Author: ![langer](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@langer](https://discourse.vtk.org/u/langer)
#### Post date: [April 28, 2021, 3:50am UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/13 "2021-04-28T03:50:48Z")

</div>

I appreciate all the help, but I still have a bunch of questions.

I think I’ve done what Ben suggested above, but I’m getting errors like

```auto
CMake Error at /home/langer/lib/cmake/vtk-9.0/vtkModule.cmake:1136 (message):
Failed to determine the real target for the `CommonCore` module. Is a
`find_package` missing a required component?

```

My `find_package` call looks like this:

```auto
find_package(VTK
 COMPONENTS
    CommonCore
    CommonDataModel
    CommonExecutionModel
    CommonTransforms
    [and a bunch more]
)

```

Does the word “component” in the error message mean that something is missing from the `COMPONENTS` section of the find\_package arguments, or is it being used in a non-technical sense to mean that some other arguments are missing?

CMakeError.log only contains errors regarding pthreads (?!), but none of the fixes for that that I found on-line made any difference. Is that something I need to be worried about?

Is `foo` in the example a literal `foo` or do I need to replace it with something? I have been assuming it’s a placeholder for something that doesn’t matter because I’m not actually building anything with this code.

The Ubuntu 18 system that I’m using only has cmake 3.10, so I changed the minimum version number. Will that matter? I got the same results on a newer Ubuntu with a newer cmake, \> 3.13.

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: [April 28, 2021, 1:56pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/14 "2021-04-28T13:56:35Z")

</div>

> [@langer](#):
>
> What happens when a project wants to use vtk but also links with a library that requires a different build system, other than cmake?

VTK provides its usage API as CMake code and a CMake API. Other build systems would need to figure out how to utilize VTK’s autoinit system on their own. It doesn’t change that often, so doing the “see what VTK’s CMake API does and copy it into a static header in my project” is probably sufficient.

As for the error you’re seeing, it looks like `VTK::CommonCore` is not a target at some location. Could you please provide the full callstack?

---

<div class="post-metadata">

### Author: ![langer](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@langer](https://discourse.vtk.org/u/langer)
#### Post date: [April 28, 2021, 3:07pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/15 "2021-04-28T15:07:11Z")

</div>

> [@ben.boeckel](#):
>
> As for the error you’re seeing, it looks like `VTK::CommonCore` is not a target at some location. Could you please provide the full callstack?

This is the screen output.

```auto
CMake Error at /home/langer/lib/cmake/vtk-9.0/vtkModule.cmake:1136 (message):
  Failed to determine the real target for the `CommonCore` module. Is a
  `find_package` missing a required component?
Call Stack (most recent call first):
  /home/langer/lib/cmake/vtk-9.0/vtkModule.cmake:2865 (_vtk_module_real_target)
  CMakeLists.txt:43 (vtk_module_autoinit)

```

I’ve uploaded the logs.  
Thanks!

[CMakeError.log](https://discourse.vtk.org/uploads/short-url/w7mySUzAGGtXsRHjqJ4BAw7zlQB.log) (2.6 KB) [CMakeOutput.log](https://discourse.vtk.org/uploads/short-url/zBvsiL3hSNyO2dpEAgvjOOTxlEZ.log) (50.5 KB)

---

<div class="post-metadata">

### Author: ![langer](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@langer](https://discourse.vtk.org/u/langer)
#### Post date: [April 28, 2021, 3:09pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/16 "2021-04-28T15:09:33Z")

</div>

And here is the cmake file, in case I’ve completely misunderstood your suggestions!  
[CMakeLists.txt](https://discourse.vtk.org/uploads/short-url/5X5vrOvVGWhuzJRGVpLDGOVy69M.txt) (1.7 KB)

---

<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: [April 28, 2021, 3:41pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/17 "2021-04-28T15:41:12Z")

</div>

Ah.you need to do:

```auto
vtk_module_autoinit(TARGETS foo MODULES VTK::CommonCore)

```

The components are the post-`::` part of the targets; `VTK` is the package part.

---

<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: [April 28, 2021, 3:44pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/18 "2021-04-28T15:44:00Z")

</div>

[This MR](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/7905) improves the error message in this case.

---

<div class="post-metadata">

### Author: ![langer](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@langer](https://discourse.vtk.org/u/langer)
#### Post date: [April 28, 2021, 4:51pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/19 "2021-04-28T16:51:35Z")

</div>

That was very helpful, in that it did generate a .h file containing the right sort of `#define`s, but when they’re inserted into my program before `#include <vtkAutoInit.h>` I still get the same errors.

This is in vtkutils.C

```auto
#define vtkIOExportGL2PS_AUTOINIT 1(vtkIOExportGL2PS)
#define vtkRenderingCore_AUTOINIT 4(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingOpenGL2,vtkRenderingUI)
#define vtkRenderingOpenGL2_AUTOINIT 1(vtkRenderingGL2PSOpenGL2)
#include <vtkAutoInit.h>

void initialize_vtk() {
  VTK_MODULE_INIT(CommonCore);
 [etc]
}

```

and this is the output when compiling vtkutils.C:

```auto
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-gnDdqE/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -g -UNDEBUG -DDEBUG -I/usr/include/python2.7 -I/home/langer/include/vtk-9.0 -Ibuild/temp.linux-x86_64-2.7-3d/SRC -ISRC -I/usr/include/python2.7 -I/home/langer/include/vtk-9.0 -c ./SRC/common/IO/vtkutils.C -o build/temp.linux-x86_64-2.7-3d/./SRC/common/IO/vtkutils.o -std=c++11
In file included from ./SRC/common/IO/vtkutils.C:60:0:
./SRC/common/IO/vtkutils.C: In function ‘void initialize_vtk()’:
/home/langer/include/vtk-9.0/vtkAutoInit.h:88:3: error: expected identifier before ‘{’ token
   { \
   ^
./SRC/common/IO/vtkutils.C:83:5: note: in expansion of macro ‘VTK_MODULE_INIT’
     VTK_MODULE_INIT(CommonCore);
     ^ ~~~~~~~~~~~~~~
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

```

Has the syntax for `VTK_MODULE_INIT` changed? I assume I need a `VTK_MODULE_INIT` line for each of the components that I got from `FindNeededModules`. I’ve tried prefixing “vtk” or “vtk::” to the module name but even if that’s what’s wrong it doesn’t change the results.

Thanks again.

---

<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: [April 28, 2021, 5:11pm UTC](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632/20 "2021-04-28T17:11:16Z")

</div>

I think you can just drop `VTK_MODULE_INIT` if you’re using the code that got generated. I don’t think VTK generates that macro at all (other than through the expansions in `vtkAutoInit.h`.

[Next page](https://discourse.vtk.org/t/vtk-module-init-in-9-0-1/5632.md?page=2)
