undefined reference to vtkAOSDataArrayTemplate

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.

The missing symbols for templates with MSYS2 is a known problem (see issue 18444). Unfortunately, there is currently no known fix.

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):
///@{
  /**
   * 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:
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:
///@{
  /**
   * 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

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

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.