Compile error when use VTK static library in QT Creator

(Edward) #1


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

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.

(Ben Boeckel) #2

It looks like you’re not linking to vtkCommonCore.

(Edward) #3

Thanks, I have already linked all VTK library files.

(Ben Boeckel) #4

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?

(Edward) #5

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


(Ben Boeckel) #6

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

(Edward) #7

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.