# undefined reference to vtkAOSDataArrayTemplate

**URL:** https://discourse.vtk.org/t/undefined-reference-to-vtkaosdataarraytemplate/9643
**Category:** Support
**Created:** [October 19, 2022, 12:13am UTC](https://discourse.vtk.org/t/undefined-reference-to-vtkaosdataarraytemplate/9643 "2022-10-19T00:13:41Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![BlueKnight7](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@BlueKnight7](https://discourse.vtk.org/u/BlueKnight7)
#### Post date: [October 19, 2022, 12:13am UTC](https://discourse.vtk.org/t/undefined-reference-to-vtkaosdataarraytemplate/9643/1 "2022-10-19T00:13:41Z")

</div>

I have MSYS2 installed on my Windows 10 box. I’ve installed vtk via pacman with mingw-w64-x86\_64-vtk; this is vtk 9.2.2. I’m using gcc 12.2 and is the only version of gcc that I currently have available in the MSYS2 install.

The code that I’m trying to build works fine on Linux with vtk 9.1 and gcc 4.8.5

I’ve defined the following:

vtkDoubleArray\* distArray =  
vtkArrayDownCast(input-\>GetCellData()-\>GetArray(“Distance”));

For which I see the following error:  
D:/msys64/home/roger/GitRepos/CCCCC/Code/sssIntersectionPolyDataCheck.cxx:338: undefined reference to `vtkAOSDataArrayTemplate::GetValue(long long) const’

Can anyone offer a suggestion on how to fix this?

Because I didn’t build vtk here and only have the install via pacman, I suspect that I can’t alter the vtk source for this.

---

<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: [October 19, 2022, 2:28am UTC](https://discourse.vtk.org/t/undefined-reference-to-vtkaosdataarraytemplate/9643/2 "2022-10-19T02:28:17Z")

</div>

The missing symbols for templates with MSYS2 is a known problem (see [issue 18444](https://gitlab.kitware.com/vtk/vtk/-/issues/18444)). Unfortunately, there is currently no known fix.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [October 20, 2022, 7:25pm UTC](https://discourse.vtk.org/t/undefined-reference-to-vtkaosdataarraytemplate/9643/3 "2022-10-20T19:25:07Z")

</div>

Hello,

I also compile VTK with MSYS2 and I had to tweak the source code a bit.

1. Find the entire _definition_ of the offending symbol, which is located **inside** the _definition_ of the `vtkAOSDataArrayTemplate` class that looks like this (this example applies to the `GetTypedTuple()` method that errored with me):

```cpp
///@{
  /**
   * Copy the tuple at @a tupleIdx into @a tuple.
   */
  void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
    VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
  {
    const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents;
    std::copy(this->Buffer->GetBuffer() + valueIdx,
      this->Buffer->GetBuffer() + valueIdx + this->NumberOfComponents, tuple);
  }
  ///@}

```

1. Replace it with only the forward declaration:

```cpp
void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const;

```

1. Move the _definition_ of the _method_ to **outside** the _definition_ of the _class_, that is, after the closing curly brace of the `class ... {...};` structure:

```cpp
///@{
  /**
   * Copy the tuple at @a tupleIdx into @a tuple.
   */
  template <class ValueTypeT>
  void vtkAOSDataArrayTemplate<ValueTypeT>::GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
    VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
  {
    const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents;
    std::copy(this->Buffer->GetBuffer() + valueIdx,
      this->Buffer->GetBuffer() + valueIdx + this->NumberOfComponents, tuple);
  }
  ///@}

```

This way I could get around that kind of error.

I hope this helps,

Paulo

---

<div class="post-metadata">

### Author: ![BlueKnight7](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@BlueKnight7](https://discourse.vtk.org/u/BlueKnight7)
#### Post date: [October 30, 2022, 7:39pm UTC](https://discourse.vtk.org/t/undefined-reference-to-vtkaosdataarraytemplate/9643/4 "2022-10-30T19:39:24Z")

</div>

Paulo,

I apologize for taking so long to get back on this.

I didn’t use your approach because I was using the pre-built Vtk module for MSYS2 and installed with pacman.

What I discovered in the mean time is that my error occurs if I set -g or -O0 on the compiler flags. If I set -O1, -O2, or -O3, I compile my code just fine and don’t see the problem.

To me, this does appear as a compiler bug (or what ever one wants to call it). At least I have something that works.

Thanks for all who responded.

BK

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [October 31, 2022, 5:40pm UTC](https://discourse.vtk.org/t/undefined-reference-to-vtkaosdataarraytemplate/9643/5 "2022-10-31T17:40:32Z")

</div>

Yes, unfortunately often you can’t enable optimization falgs for the debug version for numerous reasons. And, yes, it is likely a lurking bug in MinGW64 triggered by the way it preprocesses templates, which is not yet full C++11 compliant. Personally, I don’t like mixing template definitions and their implementations in the headers, but the way the VTK developers did is not illegal and is supposed to be supported.
