vtk python wrapper problem with compilation

Hi everyone, I have a problem with compilation files for wrapping

there is my cmake file

CMAKE_MINIMUM_REQUIRED(VERSION 3.3)

PROJECT(vtkExamplePython)

#C++11 flags
set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -Wall -std=c++11”)

FIND_PACKAGE(VTK REQUIRED
vtkCommonCore
vtkCommonDataModel
vtkWrappingPythonCore
)

INCLUDE(${VTK_USE_FILE})

#Python and vtk wrapping
include(vtkWrapPython)

SET(PYTHON_LIBRARIES /Library/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6.dylib)
SET(PYTHON_INCLUDE_DIRS /Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS}

${VTK_USE_FILE})

#######################################
#Building vtkExample
ADD_LIBRARY(vtkExample MODULE vtkExample.cpp)
TARGET_LINK_LIBRARIES(vtkExample ${VTK_LIBRARIES})
if(APPLE)
set_target_properties(vtkExample PROPERTIES SUFFIX “.so”)
endif()
#######################################
#Wrapping vtkExample
vtk_wrap_python3(vtkExamlePython vtkExamplePython_SRCS vtkExample.cpp)

MESSAGE(“vtkExamplePython_SRCS = ${vtkExamplePython_SRCS}”)

add_library(vtkExamplePythonD {vtkExamplePython_SRCS} vtkExample.cpp) target_link_libraries(vtkExamplePythonD {VTK_LIBRARIES}
vtkWrappingPythonCore
${VTK_PYTHON_LIBRARIES})

add_library(vtkExamplePython MODULE vtkExamplePythonInit.data)
set(VTK_MODULES_USED vtkCommonDataModel vtkCommonCore)
set(VTK_PYTHOND_LIBS)
foreach(TMP_LIB {VTK_MODULES_USED}) set(VTK_PYTHOND_LIBS {VTK_PYTHOND_LIBS} ${TMP_LIB}PythonD)
endforeach()

target_link_libraries(vtkExamplePython vtkExamplePythonD ${VTK_PYTHOND_LIBS})

set_target_properties(vtkExamplePython PROPERTIES PREFIX “”)
if(WIN32 AND NOT CYGWIN)
set_target_properties(vtkExamplePython PROPERTIES SUFFIX “.pyd”)
endif(WIN32 AND NOT CYGWIN)

==============================================================

This file compiles nice with cmake, but when I run make, I have an error

[ 11%] Python Wrapping - generating vtkExamplePythonInit.cxx
make[2]: *** No rule to make target /Users/idaymand/workspace/vtkExample/src/vtkExampleHierarchy', needed byvtkExamplePython.cxx’. Stop.
make[1]: *** [CMakeFiles/vtkExamplePythonD.dir/all] Error 2
make: *** [all] Error 2

I make subfolder ./vtkExampleHierarchy in folder src, compile cmake again, and after that, run make and getting

[ 11%] Python Wrapping - generating vtkExamplePythonInit.cxx
[ 22%] Python Wrapping - generating vtkExamplePython.cxx

And this state is staying long time without changes, till I do break process.

Help me please!!! What I do done not right?
Thanks

Which version of VTK are you using? For VTK 7 and 8, the solution in this thread might work for you. (Note that although the solution in that thread checks for (${VTK_VERSION} VERSION_EQUAL "8.1"), the same solution should work for 8.2).

I am using 8.2_0.4 version of vtk

Hi David,
Thank you for a help,

I inserted block with hierarchy before call vtk_wrap_python3 and now I have again a long time of compilation with message

make
Scanning dependencies of target vtkGeodesicHierarchy
[ 10%] For vtkGeodesic - updating vtkGeodesicHierarchy.txt

Help me please to solve this problem!
Thanks

https://bitbucket.org/InnaDaymand/vtkgeodesic/src/master/src/CMakeLists.txt

this is link on my make file

also I your file vtkWrapHierarchy.cmake for include in my cmake file.

But I have a same effect - I can’t compile module

============================================================
10:59:34 **** Build of configuration Default for project vtkGeodesic ****

make
Scanning dependencies of target vtkGeodesicHierarchy
[ 10%] For vtkGeodesic - updating vtkGeodesicHierarchy.txt

this commands hands up

/usr/local/Cellar/vtk/8.2.0_4/bin/vtkWrapHierarchy-8.2 @vtkGeodesicHierarchy…args -o /Users/idaymand/workspace/vtkGeodesic/Debug/vtkGeodesicHierarchy.txt vtkGeodesicHierarchy.data

==========================
file GeodesicHierarchy…args

-I"/usr/local/Cellar/vtk/8.2.0_4/include/vtk-8.2"

-I"/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/include/python3.7m"

-I"/Users/idaymand/workspace/vtkGeodesic/src"

-I"/usr/local/Cellar/vtk/8.2.0_4/lib/cmake/vtk-8.2/UseVTK.cmake"

-I"/usr/local/Cellar/vtk/8.2.0_4/include/vtk-8.2"

=========================
/Users/idaymand/workspace/vtkGeodesic/Debug/vtkGeodesicHierarchy.txt
this file is not exist

=========================
file vtkGeodesicHierarchy.data

/Users/idaymand/workspace/vtkGeodesic/src/vtkGeodesic.h;vtkGeodesic

=========================

I am right understand, that file
/Users/idaymand/workspace/vtkGeodesic/Debug/vtkGeodesicHierarchy.txt
is output?

Thanks

Hi David,
I researched my problem with stand up of vtkWrapHierarchy-8.2 by process of parsing headers, and I think, that I have a problem with description of head file.

Below is link on my header file, can you look please, may be something need add?

https://bitbucket.org/InnaDaymand/vtkgeodesic/src/master/src/vtkGeodesic.h

Thanks

Hi Inna,

You are correct that there is a problem parsing the header, it is triggered by this code:

","<<axes_x.GetY();

This is very strange, because it works fine if spaces are added:

"," << axes_x.GetY();

It’s a little mystery that I can investigate.

For wrapping with VTK 8.2, see the cmake code below. Note that I removed “MODULE” from the first add_library(). The only thing that should be built as a module is the python module, vtkGeodesicPython.so (or .pyd on Windows).

The PROPERTY POSITION_INDEPENDENT_CODE ON is needed in case you are doing a static build on a 64-bit linux (or mac) system and linking the static libraries to the python module (it enables the ‘-fPIC’ option of the compiler).

#######################################
# Building vtkGeodesic
add_library(${LIB_NAME} vtkGeodesic.cpp)
target_link_libraries(${LIB_NAME} ${VTK_LIBRARIES})

#######################################
# Wrapping vtkGeodesic
set(MODULE_HIERARCHY_NAME ${LIB_NAME}Hierarchy)
# All libs mentioned here must be listed in the find_package(VTK ...) 
set(${LIB_NAME}_LINK_DEPENDS vtkCommonCore vtkCommonDataModel)
set(${LIB_NAME}_WRAP_DEPENDS vtkCommonCore vtkCommonDataModel)

set(OTHER_HIERARCHY_FILES)
foreach(dep ${${LIB_NAME}_LINK_DEPENDS})
  list(APPEND OTHER_HIERARCHY_FILES "${${dep}_WRAP_HIERARCHY_FILE}")
endforeach()

include(vtkWrapHierarchy)
vtk_wrap_hierarchy(${LIB_NAME} ${CMAKE_CURRENT_BINARY_DIR} "${LIB_SRCS}")
set(KIT_HIERARCHY_FILE ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_HIERARCHY_NAME}.txt)
set(LIB_HIERARCHY_STAMP ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_HIERARCHY_NAME}.stamp.txt)

vtk_wrap_python3(${LIB_NAME}Python ${LIB_NAME}Python_SRCS vtkGeodesic.cpp)

MESSAGE("vtkGeodesicPython_SRCS = ${vtkGeodesicPython_SRCS}")

add_library(${LIB_NAME}PythonD ${${LIB_NAME}Python_SRCS} vtkGeodesic.cpp)
set_property(TARGET ${LIB_NAME}PythonD
        PROPERTY POSITION_INDEPENDENT_CODE ON)

target_link_libraries(${LIB_NAME}PythonD
        ${VTK_LIBRARIES}
        vtkWrappingPythonCore
        ${VTK_PYTHON_LIBRARIES})

add_library(${LIB_NAME}Python MODULE ${LIB_NAME}PythonInit.cxx)

set(VTK_MODULES_USED vtkCommonDataModel vtkCommonCore)

set(VTK_PYTHOND_LIBS)

foreach(TMP_LIB ${VTK_MODULES_USED})
   set(VTK_PYTHOND_LIBS ${VTK_PYTHOND_LIBS} ${TMP_LIB}PythonD)
endforeach()

target_link_libraries(${LIB_NAME}Python ${LIB_NAME}PythonD ${VTK_PYTHOND_LIBS})

set_target_properties(${LIB_NAME}Python PROPERTIES PREFIX "")
if(WIN32 AND NOT CYGWIN)
    set_target_properties(${LIB_NAME}Python PROPERTIES SUFFIX ".pyd")
endif(WIN32 AND NOT CYGWIN)

Hi David,
thank you very mush for your help, I got a file vtkGeodesicPython.so.

But in Python

import vtkGeodesicPython

does not work, symbol not resolved before running.

I work with Python 3.6, may be problem in this?

I tried to find where I am connecting version of library Python 3.7 in my cmake file, but not found.

I saved this file in subfolder ./lib, this subfolder is registered in PYTHONPATH of project.

Help me please to understand what I do not right.

Thanks

What symbol is not resolved? How is your VTK installed?

I am working on the Mac Sierra, in Eclipse with plugin PyDev, and using Python 3.6

I installed VTK with homebrew (homebrew install vtk).

I write
import vtkGeodesicPython

in python file, and I am getting information, that import not resolved. If I trace this line in debug, my Python is crashing.

Also need note, that I haven’t____init__.py I didn’t get it as result of compilation.

According to the homebrew page, their VTK package uses Python 3.7.5. So if you want to use homebrew’s VTK, you must use homebrew’s Python 3.7.

If your project requires Python 3.6, then you will have to build VTK with Python 3.6.

Hi David,

I researched a question with version, and I have following data

  1. With Python 3.6 is delivering vtk 8.1.2 for mac os sierra
  2. on the site download VTK there is only version 8.2.0 or 7.1.1 and lower.

What should I do? Download for c version of VTK 8.2.0 and use headers from it, but compile with library 8.1.2 from python?

Thanks a lot

You should use the Python 3.7 and VTK that comes with Homebrew, since you have already installed it.

Why are you using Python 3.6?

I am working in project that uses python 3.6 with vtk.

This is big project, and my job in it - is doing wrapper from c++ to python for realisation of critical important in terms of speed algorithm

I can not change version of python

May be, I can use headers from vtk 8.2 from homebrew, but by link include libraries from vtk 8.1.2?

Then your only choice is to download the VTK 8.2 source code and build VTK yourself.

May be, I can use headers from vtk 8.2 from homebrew, but by link include libraries from vtk 8.1.2?

No, you cannot use the VTK 8.2 headers with VTK 8.1.2 libraries.

One more question,

if I build VTK myself and build library with it, will i can use vtk 8.1.2 package for python 3.6 with my library? Or it must be use only VTK which i build myself?

Your library can only be used with the version of VTK that you use to build it.