[vtkusers] Linking static VTK to simple Qt app

Gib Bogle g.bogle at auckland.ac.nz
Wed Sep 22 22:32:05 EDT 2010


Hi,
Sorry to go on about this, but I am really stuck.  On Windows, using  
MinGW-4.4.0, I've built the VTK libraries statically, and the examples  
work.  Now I'm trying to use the static libraries with Qt, building  
with QtCreator.  I've now gone back to a very simple test program  
which works with shared VTK libraries.  On linking I get a very long  
list of "undefined reference" errors, seemingly for a large fraction  
of the functions in the libraries (see the end of this post for a  
sample).  I was planning to just post the link command:

g++ -enable-stdcall-fixup -Wl,-enable-auto-import  
-Wl,-enable-runtime-pseudo-reloc -Wl,-s -mthreads -Wl  
-Wl,-subsystem,windows -o release\QVTK_test-static.exe  
release/mainwindow.o release/main.o release/moc_mainwindow.o   
-L"c:\Qt\4.6.3\lib" -lmingw32 -lqtmain -Lc:\VTK-build-4.4.0-static\bin  
-lQVTK -lvtkCommon -lvtkRendering -lvtkGraphics -lvtkFiltering  
-lQtGui4 -lQtCore4

then I decided I might as well post the source code as well, since  
it's so short (see below).  Maybe someone can see something obviously  
wrong with the link command that qmake is generating.

//----------------------------------------------------------------------
// mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QVTKWidget.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include "vtkCylinderSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkCamera.h"

QT_BEGIN_NAMESPACE
class QAction;
class QMenu;
class QMdiArea;
class QMdiSubWindow;
class QSignalMapper;
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
     Q_OBJECT

public:
     MainWindow();

protected:
     void closeEvent(QCloseEvent *event);
     QMdiArea *mdiArea;
	QWidget *myQwidget;
	QVTKWidget* qvtkWidget;
	vtkRenderer* ren;
	FILE *fp;
};

#endif

//-------------------------------------------------------------------
// main.cpp
#include <QApplication>

#include "mainwindow.h"

int main(int argc, char *argv[])
{
     QApplication app(argc, argv);
     MainWindow mainWin;
     mainWin.show();
	QRect r = mainWin.geometry();
	r.setWidth(800);
	r.setHeight(600);
	mainWin.setGeometry(r);
	r = mainWin.geometry();
     return app.exec();
}

//--------------------------------------------------------------------
// mainwindow.cpp
#include <QtGui>

#include "mainwindow.h"

MainWindow::MainWindow()
{
     mdiArea = new QMdiArea;
     mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
     mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
     setCentralWidget(mdiArea);

     setWindowTitle(tr("MDI"));
     setUnifiedTitleAndToolBarOnMac(true);

	QRect r = mdiArea->geometry();
	r.setWidth(400);
	r.setHeight(300);
	mdiArea->setGeometry(r);


	// Create a QVTKWidget, and a layout, and add the widget to the layout
	qvtkWidget = new QVTKWidget(this,QFlag(0));
	QVBoxLayout *layout = new QVBoxLayout;
     layout->addWidget(qvtkWidget);

	// Associate the layout with mdiArea
     mdiArea->setLayout(layout);

	// Create a renderer, and add it to qvtkWidget's render window.
	// The renderer renders into the render window.
	ren = vtkRenderer::New();
     vtkRenderWindow *renWin = qvtkWidget->GetRenderWindow();
     renWin->AddRenderer(ren);

	vtkCylinderSource *cylinder = vtkCylinderSource::New();
	cylinder->SetResolution(18);

	vtkPolyDataMapper *cylinderMapper = vtkPolyDataMapper::New();
	cylinderMapper->SetInputConnection(cylinder->GetOutputPort());

	vtkActor *cylinderActor1 = vtkActor::New();
	cylinderActor1->SetMapper(cylinderMapper);
	cylinderActor1->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
	cylinderActor1->RotateX(30.0);
	cylinderActor1->RotateZ(-45.0);
	vtkActor *cylinderActor2 = vtkActor::New();
	cylinderActor2->SetMapper(cylinderMapper);
	cylinderActor2->GetProperty()->SetColor(0.2, 0.6, 0.4);

	// Position the actors
	int x, y, z;
	x = 0;
	y = 0;
	z = 0;
     cylinderActor1->SetPosition(x, y, z);
	x = 5;
	y = 2;
	z = 5;
     cylinderActor2->SetPosition(x, y, z);

	ren->AddActor(cylinderActor1);
	ren->AddActor(cylinderActor2);
	ren->SetBackground(0.1, 0.2, 0.4);

	ren->ResetCamera();
	ren->GetActiveCamera()->Zoom(1.5);

	vtkRenderWindowInteractor *iren = qvtkWidget->GetInteractor();
	iren->Initialize();
}

void MainWindow::closeEvent(QCloseEvent *event)
{
	event->accept();
}

//----------------------------------------------------------------------
Sample of link errors:

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkObjectFactory.cxx.obj):vtkObjectFactory.cxx:(.text+0x109c): undefined reference to  
`vtksys::Directory::Directory()'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkObjectFactory.cxx.obj):vtkObjectFactory.cxx:(.text+0x10ae): undefined reference to `vtksys::Directory::Load(char  
const*)'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkObjectFactory.cxx.obj):vtkObjectFactory.cxx:(.text+0x10cb): undefined reference to `vtksys::Directory::GetNumberOfFiles()  
const'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkObjectFactory.cxx.obj):vtkObjectFactory.cxx:(.text+0x10e6): undefined reference to `vtksys::Directory::GetFile(unsigned long)  
const'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkObjectFactory.cxx.obj):vtkObjectFactory.cxx:(.text+0x14fe): undefined reference to  
`vtksys::Directory::~Directory()'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkObjectFactory.cxx.obj):vtkObjectFactory.cxx:(.text+0x1511): undefined reference to  
`vtksys::Directory::~Directory()'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkObjectFactory.cxx.obj):vtkObjectFactory.cxx:(.text+0x1520): undefined reference to  
`vtksys::Directory::~Directory()'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkWin32OutputWindow.cxx.obj):vtkWin32OutputWindow.cxx:(.text+0x2dd): undefined reference to  
`GetStockObject at 4'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkVariant.cxx.obj):vtkVariant.cxx:(.text+0x52e): undefined reference to  
`vtksys::SystemToolsManager::SystemToolsManager()'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkVariant.cxx.obj):vtkVariant.cxx:(.text+0x54e): undefined reference to  
`vtksys::SystemToolsManager::~SystemToolsManager()'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkVariant.cxx.obj):vtkVariant.cxx:(.text+0x704): undefined reference to `vtksys::SystemTools::Strucmp(char const*, char  
const*)'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkVariant.cxx.obj):vtkVariant.cxx:(.text+0x72e): undefined reference to `vtksys::SystemTools::Strucmp(char const*, char  
const*)'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkVariant.cxx.obj):vtkVariant.cxx:(.text+0x756): undefined reference to `vtksys::SystemTools::Strucmp(char const*, char  
const*)'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkVariant.cxx.obj):vtkVariant.cxx:(.text+0x76c): undefined reference to `vtksys::SystemTools::Strucmp(char const*, char  
const*)'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkVariant.cxx.obj):vtkVariant.cxx:(.text+0x796): undefined reference to `vtksys::SystemTools::Strucmp(char const*, char  
const*)'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkDynamicLoader.cxx.obj):vtkDynamicLoader.cxx:(.text+0x68): undefined reference to  
`vtksys::DynamicLoader::LastError()'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkDynamicLoader.cxx.obj):vtkDynamicLoader.cxx:(.text+0x74): undefined reference to  
`vtksys::DynamicLoader::LibExtension()'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkDynamicLoader.cxx.obj):vtkDynamicLoader.cxx:(.text+0x80): undefined reference to  
`vtksys::DynamicLoader::LibPrefix()'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkDynamicLoader.cxx.obj):vtkDynamicLoader.cxx:(.text+0x8c): undefined reference to `vtksys::DynamicLoader::GetSymbolAddress(HINSTANCE__*, char  
const*)'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkDynamicLoader.cxx.obj):vtkDynamicLoader.cxx:(.text+0x98): undefined reference to  
`vtksys::DynamicLoader::CloseLibrary(HINSTANCE__*)'

c:\VTK-build-4.4.0-static\bin/libvtkCommon.a(vtkDynamicLoader.cxx.obj):vtkDynamicLoader.cxx:(.text+0xa4): undefined reference to `vtksys::DynamicLoader::OpenLibrary(char  
const*)'

c:\VTK-build-4.4.0-static\bin/libvtkRendering.a(vtkRenderer.cxx.obj):vtkRenderer.cxx:(.text+0xfa6): undefined reference to  
`vtkAssemblyPath::GetLastNode()'

c:\VTK-build-4.4.0-static\bin/libvtkRendering.a(vtkRenderer.cxx.obj):vtkRenderer.cxx:(.text+0xfc4): undefined reference to  
`vtkAssemblyPath::GetLastNode()'

c:\VTK-build-4.4.0-static\bin/libvtkRendering.a(vtkRenderer.cxx.obj):vtkRenderer.cxx:(.text+0x104e): undefined reference to  
`vtkAssemblyPath::GetLastNode()'

c:\VTK-build-4.4.0-static\bin/libvtkRendering.a(vtkRenderer.cxx.obj):vtkRenderer.cxx:(.text+0x106c): undefined reference to  
`vtkAssemblyPath::GetLastNode()'

c:\VTK-build-4.4.0-static\bin/libvtkRendering.a(vtkRenderer.cxx.obj):vtkRenderer.cxx:(.text+0x10f6): undefined reference to  
`vtkAssemblyPath::GetLastNode()'

c:\VTK-build-4.4.0-static\bin/libvtkRendering.a(vtkRenderer.cxx.obj):vtkRenderer.cxx:(.text+0x1114): more undefined references to `vtkAssemblyPath::GetLastNode()'  
follow

c:\VTK-build-4.4.0-static\bin/libvtkRendering.a(vtkRenderer.cxx.obj):vtkRenderer.cxx:(.text+0x1734): undefined reference to  
`vtkPropCollection::New()'

c:\VTK-build-4.4.0-static\bin/libvtkRendering.a(vtkRenderer.cxx.obj):vtkRenderer.cxx:(.text+0x1b84): undefined reference to  
`vtkPropCollection::GetNumberOfPaths()'

c:\VTK-build-4.4.0-static\bin/libvtkRendering.a(vtkRenderer.cxx.obj):vtkRenderer.cxx:(.text+0x1c45): undefined reference to  
`vtkPropCollection::New()'

c:\VTK-build-4.4.0-static\bin/libvtkRendering.a(vtkRenderer.cxx.obj):vtkRenderer.cxx:(.text+0x1ca1): undefined reference to  
`vtkAssemblyPath::GetLastNode()'

c:\VTK-build-4.4.0-static\bin/libvtkRendering.a(vtkRenderer.cxx.obj):vtkRenderer.cxx:(.text+0x1ffc): undefined reference to  
`vtkMatrix4x4::New()'

c:\VTK-build-4.4.0-static\bin/libvtkRendering.a(vtkRenderer.cxx.obj):vtkRenderer.cxx:(.text+0x2059): undefined reference to `vtkMatrix4x4::DeepCopy(double*, double  
const*)'

c:\VTK-build-4.4.0-static\bin/libvtkRendering.a(vtkRenderer.cxx.obj):vtkRenderer.cxx:(.text+0x30cc): undefined reference to  
`vtkMatrix4x4::New()'


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.




More information about the vtkusers mailing list