Linking error: Undefined reference to <vtkInteractor-derived class>::New(). All VTK libraries linked, I suppose.

Greetings, all,

I’m trying to compile the code below:

#ifndef V3DMOUSEINTERACTORSTYLE_H
#define V3DMOUSEINTERACTORSTYLE_H
#include <vtkObjectFactory.h>
#include <vtkInteractorStyleTrackballCamera.h>

class v3dMouseInteractorStyle : public vtkInteractorStyleTrackballCamera
{
  public:
    static v3dMouseInteractorStyle* New();
    vtkTypeMacro(v3dMouseInteractorStyle, vtkInteractorStyleTrackballCamera);

    virtual void OnLeftButtonDown();

};

#endif

It throws an undefined reference to the New() function during linking time. I’ve read here ( vtkScalarBarActor New macro problem ) that it is likely caused by some library missing library in liking command. Here is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.7)

set(PROGNAME HorizontesPickProbe)

PROJECT(${PROGNAME})

set(CMAKE_PREFIX_PATH "C:/VTK64/install_release/lib/cmake" ${CMAKE_PREFIX_PATH})

find_package(VTK REQUIRED)

include(${VTK_USE_FILE})

set(CMAKE_AUTOMOC ON)

include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

file(GLOB_RECURSE UI_FILES *.ui)
file(GLOB_RECURSE QT_WRAP *.h)
file(GLOB_RECURSE CXX_FILES *.cpp)

qt5_wrap_ui(UISrcs ${UI_FILES} )

add_executable(${PROGNAME} ${CXX_FILES} ${UISrcs} ${QT_WRAP})

qt5_use_modules(${PROGNAME} Core Gui)

target_link_libraries(${PROGNAME} ${VTK_LIBRARIES})

Supposedly, the last line links the executable against all VTK libraries, since the CMake list does not explicitly list each library I intend to use.

Any help will be much appreciated,

Paulo

Can you paste/upload the associated .cpp file?

1 Like

Oh, thanks, the .cpp file was missing the macro that implements New(): vtkStandardNewMacro(v3dMouseInteractorStyle);