0

When I used vtk in qt creator firstly, I came into this trouble. And I cannot solve it now, asking for some help. I followed this website https://csuzhangxc.gitbooks.io/vtk-simple-tutorial/content/getting_started/the_first.html but I got this:

error: /usr/local/lib//libvtkRenderingOpenGL2-8.2.a(vtkXRenderWindowInteractor.cxx.o): undefined reference to symbol 'XGetWindowAttributes'
/usr/lib/x86_64-linux-gnu/libX11.so.6:-1: error: error adding symbols: DSO missing from command line

Somebody know what to do?

Some file of the project are following: .pro:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

DEFINES += QT_DEPRECATED_WARNINGS

INCLUDEPATH += /usr/local/include/vtk-8.2/

LIBS += -L/usr/local/lib/ \
        -lvtkGUISupportQt-8.2 \
        -lvtkIOImage-8.2 \
        -lvtkInteractionImage-8.2 \
        -lvtkRenderingCore-8.2 \
        -lvtkCommonExecutionModel-8.2 \
        -lvtkCommonCore-8.2 \
        -lvtkRenderingOpenGL2-8.2 \
        -lvtkInteractionStyle-8.2 \

SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    mainwindow.h

FORMS += \
    mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

main.cpp:

#include "mainwindow.h"


#include <QApplication>
#include<vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)


#include "vtkImageViewer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkPNGReader.h"
#include "QVTKWidget.h"
#include "vtkImageData.h"
#include "vtkActor.h"


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QVTKWidget widget;


    char filename[] = "/home/bichongke/Downloads/dinosaur.png";
    vtkPNGReader* reader =vtkPNGReader::New();
    reader->SetFileName(filename);
    reader->Update();


    vtkImageViewer* imageView = vtkImageViewer::New();
    imageView->SetInputConnection(reader->GetOutputPort());


    widget.SetRenderWindow(imageView->GetRenderWindow());
    imageView->SetupInteractor(widget.GetRenderWindow()->GetInteractor());
    imageView->SetColorLevel(138.5);
    imageView->SetColorWindow(233);


    int* dims = reader->GetOutput()->GetDimensions();
    widget.resize(dims[0],dims[1]);
    widget.show();


    a.exec();
    imageView->Delete();
    reader->Delete();
    return 0;
    //MainWindow w;
    //w.show();
    //return a.exec();
}
4
  • The library you are using depends on something, which could not be found.
    – scopchanov
    Commented Oct 31, 2020 at 13:44
  • Is something wrong with my system? Or just I missed a link to a library in the project? I appreciate your help.
    – YueMingyu
    Commented Nov 1, 2020 at 12:56
  • I think vtk is looking for xlib.
    – scopchanov
    Commented Nov 1, 2020 at 20:39
  • Could you please show me how to add x11 to the vtk? I tried many ways but it did not work. Should I add x11 in the vtk's file or the qt project's file?
    – YueMingyu
    Commented Nov 3, 2020 at 2:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.