Compile error when use VTK static library in QT Creator

Hi,

I’m trying to use VTK static lib in QT Creator, but got so many compile error(> 2000), if I compile the same program with VTK dynamic lib, no error and the program works well.

I have already add all VTK libraries in the pro file, and also changed vtkConfigure.h follow the instruction in https://forum.qt.io/topic/950/problem-linking-a-foreign-static-library/4

but can’t fix the problem yet.

Below are some error I got:

/home/edward/workings/vtk/vtk-static/lib/libvtkCommonColor-8.2.a(vtkNamedColors.cxx.o): In function vtkNamedColors::GetColorNames(vtkStringArray*)': /home/edward/workings/vtk/VTK-8.2.0/Common/Color/vtkNamedColors.cxx:1027: undefined reference tovtkStringArray::InsertNextValue(vtkStdString)’
/home/edward/workings/vtk/vtk-static/lib/libvtkCommonExecutionModel-8.2.a(vtkAlgorithm.cxx.o): In function vtkAlgorithm::vtkAlgorithm()': /home/edward/workings/vtk/VTK-8.2.0/Common/ExecutionModel/vtkAlgorithm.cxx:94: undefined reference tovtkInformationVector::New()’
/home/edward/workings/vtk/VTK-8.2.0/Common/ExecutionModel/vtkAlgorithm.cxx:95: undefined reference to vtkInformationVector::New()' /home/edward/workings/vtk/VTK-8.2.0/Common/ExecutionModel/vtkAlgorithm.cxx:97: undefined reference tovtkInformation::New()’
/home/edward/workings/vtk/vtk-static/lib/libvtkCommonExecutionModel-8.2.a(vtkAlgorithm.cxx.o): In function `vtkAlgorithm::GetInputArrayFieldInformation(int, vtkInformationVector**)’:

Thanks in advance.

It looks like you’re not linking to vtkCommonCore.

Thanks, I have already linked all VTK library files.

The linker thinks you’re not. The order of the libraries also matters for static linking on Linux. Could you paste the full link line that is being used?

Yes, you are right.
It seems like the libraries should be linked in some order, I don’t solve the problem yet, but the error reduce to 30+ now

Thanks!

You’ll generally want libhighlevel.a liblowlevel.a ordering (so vtkRenderingOpenGL2 before vtkRenderingCore).

Thanks every body!

Following the rule offered by Ben Boeckel, I have solved the problem.

A simple way is: move the lib with link error ahead in the link command , and you will finally get the right order.

Thanks again.

Hi, Edward!
I have the same problems as you got. And I have no idea about the rank levels of the all VTK static libraries. Can you tell me the method of making this ranking list?

Thanks!

The easiest is to just use CMake as it will order things properly. The most reliable way is to have CMake generate a project that links to the libraries you want and to grab the order from the link line.