I am trying to build the CylinderExample with VTK. I am on ubuntu 20.04 LTS and installed VTK with vcpkg. The project is built with CMake.
However, the CMake initialization command fails:
Skipping CylinderExample: Could not find the VTK package with the following required components: RenderingContextOpenGL2.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ilmu011/Desktop/CylinderExample/build
Here is my CMakeLists.txt. I had to edit it slightly from the given one on the website since I built it with vcpkg
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_TOOLCHAIN_FILE /home/ilmu011/Desktop/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "")
set(VCPKG_TARGET_TRIPLET "x64-linux" CHACHE STRING)
set(CMAKE_PREFIX_PATH
/home/ilmu011/Desktop/vcpkg/installed/x64-linux/share/vtk
)
project(CylinderExample, LANGUAGES CXX)
find_package(VTK COMPONENTS
vtkCommonColor
vtkCommonCore
vtkFiltersSources
vtkInteractionStyle
vtkRenderingContextOpenGL2
vtkRenderingCore
vtkRenderingFreeType
vtkRenderingGL2PSOpenGL2
vtkRenderingOpenGL2
QUIET
)
if (NOT VTK_FOUND)
message("Skipping CylinderExample: ${VTK_NOT_FOUND_MESSAGE}")
return()
endif()
message (STATUS "VTK_VERSION: ${VTK_VERSION}")
if (VTK_VERSION VERSION_LESS "8.90.0")
# old system
include(${VTK_USE_FILE})
add_executable(CylinderExample MACOSX_BUNDLE CylinderExample.cxx )
target_link_libraries(CylinderExample PRIVATE ${VTK_LIBRARIES})
else()
# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")
add_executable(CylinderExample MACOSX_BUNDLE CylinderExample.cxx )
target_link_libraries(CylinderExample PRIVATE ${VTK_LIBRARIES})
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS CylinderExample
MODULES ${VTK_LIBRARIES}
)
endif()
I just built vtk from source as the document describes, but it still doesn’t work. It’s weird. The cmake command works as it should:
ilmu011@ilmu011-VirtualBox:~/Desktop/CylinderExample$ cmake -S source -B build
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Skipping CylinderExample:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ilmu011/Desktop/CylinderExample/build
However, when I run make, nothing happens. No text output, nothing and no executable is made.
I used the exact source file and cmake file, the only thing I changed in the CMakeLists.txt is add the line
set(CMAKE_PREFIX_PATH
~/Desktop/vtk
)
in the 2nd line to provide the vtk directory in the cmake file so I don’t have to do it in the command.
@mwestfal This might be related to a bug in the VTK 9.0 configuration, where vtkRenderingContextOpenGL2 was accidentally left out of the default build. See !7646 for more information.
When I tried your suggestion of deleting the lines using the vcpkg installation (9.0.3), the previous error about not finding the package disappeared. However, trying to build the program with make generates this:
ilmu011@ilmu011-VirtualBox:~/Desktop/CylinderExample/build$ make
[ 50%] Building CXX object CMakeFiles/CylinderExample.dir/CylinderExample.cxx.o
[100%] Linking CXX executable CylinderExample
/usr/bin/ld: /home/ilmu011/Desktop/vcpkg/installed/x64-linux/lib/libfreetype.a(sfnt.c.o): in function `Load_SBit_Png':
sfnt.c:(.text+0x627c): undefined reference to `png_create_read_struct'
/usr/bin/ld: sfnt.c:(.text+0x6292): undefined reference to `png_create_info_struct'
/usr/bin/ld: sfnt.c:(.text+0x62b6): undefined reference to `png_set_longjmp_fn'
/usr/bin/ld: sfnt.c:(.text+0x62f7): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: sfnt.c:(.text+0x634a): undefined reference to `png_set_read_fn'
/usr/bin/ld: sfnt.c:(.text+0x6359): undefined reference to `png_read_info'
/usr/bin/ld: sfnt.c:(.text+0x638a): undefined reference to `png_get_IHDR'
/usr/bin/ld: sfnt.c:(.text+0x63e0): undefined reference to `png_set_expand_gray_1_2_4_to_8'
/usr/bin/ld: sfnt.c:(.text+0x63f4): undefined reference to `png_get_valid'
/usr/bin/ld: sfnt.c:(.text+0x6432): undefined reference to `png_set_interlace_handling'
/usr/bin/ld: sfnt.c:(.text+0x6446): undefined reference to `png_set_filler'
/usr/bin/ld: sfnt.c:(.text+0x6455): undefined reference to `png_read_update_info'
/usr/bin/ld: sfnt.c:(.text+0x6486): undefined reference to `png_get_IHDR'
/usr/bin/ld: sfnt.c:(.text+0x64cc): undefined reference to `png_set_read_user_transform_fn'
/usr/bin/ld: sfnt.c:(.text+0x6597): undefined reference to `png_read_image'
/usr/bin/ld: sfnt.c:(.text+0x65a6): undefined reference to `png_read_end'
/usr/bin/ld: sfnt.c:(.text+0x6619): undefined reference to `png_set_gray_to_rgb'
/usr/bin/ld: sfnt.c:(.text+0x6631): undefined reference to `png_set_packing'
/usr/bin/ld: sfnt.c:(.text+0x6641): undefined reference to `png_set_tRNS_to_alpha'
/usr/bin/ld: sfnt.c:(.text+0x6650): undefined reference to `png_set_palette_to_rgb'
/usr/bin/ld: sfnt.c:(.text+0x6663): undefined reference to `png_set_strip_16'
/usr/bin/ld: sfnt.c:(.text+0x667d): undefined reference to `png_set_read_user_transform_fn'
/usr/bin/ld: sfnt.c:(.text+0x66b4): undefined reference to `png_destroy_read_struct'
/usr/bin/ld: /home/ilmu011/Desktop/vcpkg/installed/x64-linux/lib/libfreetype.a(sfnt.c.o): in function `error_callback':
sfnt.c:(.text+0x6759): undefined reference to `png_get_error_ptr'
/usr/bin/ld: sfnt.c:(.text+0x6773): undefined reference to `png_set_longjmp_fn'
/usr/bin/ld: /home/ilmu011/Desktop/vcpkg/installed/x64-linux/lib/libfreetype.a(sfnt.c.o): in function `read_data_from_FT_Stream':
sfnt.c:(.text+0x9d59): undefined reference to `png_get_io_ptr'
/usr/bin/ld: sfnt.c:(.text+0x9d95): undefined reference to `png_get_error_ptr'
/usr/bin/ld: sfnt.c:(.text+0x9da5): undefined reference to `png_error'
/usr/bin/ld: /home/ilmu011/Desktop/vcpkg/installed/x64-linux/lib/libfreetype.a(sfnt.c.o): in function `sfnt_init_face':
sfnt.c:(.text+0x1313e): undefined reference to `BrotliDecoderDecompress'
/usr/bin/ld: /home/ilmu011/Desktop/vcpkg/installed/x64-linux/lib/libfreetype.a(ftbzip2.c.o): in function `ft_bzip2_stream_close':
ftbzip2.c:(.text+0x7d): undefined reference to `BZ2_bzDecompressEnd'
/usr/bin/ld: /home/ilmu011/Desktop/vcpkg/installed/x64-linux/lib/libfreetype.a(ftbzip2.c.o): in function `ft_bzip2_file_fill_output':
ftbzip2.c:(.text+0x127): undefined reference to `BZ2_bzDecompress'
/usr/bin/ld: /home/ilmu011/Desktop/vcpkg/installed/x64-linux/lib/libfreetype.a(ftbzip2.c.o): in function `ft_bzip2_stream_io':
ftbzip2.c:(.text+0x378): undefined reference to `BZ2_bzDecompressEnd'
/usr/bin/ld: ftbzip2.c:(.text+0x3c7): undefined reference to `BZ2_bzDecompressInit'
/usr/bin/ld: /home/ilmu011/Desktop/vcpkg/installed/x64-linux/lib/libfreetype.a(ftbzip2.c.o): in function `FT_Stream_OpenBzip2':
ftbzip2.c:(.text+0x604): undefined reference to `BZ2_bzDecompressInit'
/usr/bin/ld: /home/ilmu011/Desktop/vcpkg/installed/x64-linux/lib/libfreetype.a(ftgzip.c.o): in function `ft_gzip_stream_close':
ftgzip.c:(.text+0x1dd): undefined reference to `inflateEnd'
/usr/bin/ld: /home/ilmu011/Desktop/vcpkg/installed/x64-linux/lib/libfreetype.a(ftgzip.c.o): in function `ft_gzip_file_fill_output':
ftgzip.c:(.text+0x2b1): undefined reference to `inflate'
/usr/bin/ld: /home/ilmu011/Desktop/vcpkg/installed/x64-linux/lib/libfreetype.a(ftgzip.c.o): in function `ft_gzip_file_io':
ftgzip.c:(.text+0x505): undefined reference to `inflateReset'
/usr/bin/ld: /home/ilmu011/Desktop/vcpkg/installed/x64-linux/lib/libfreetype.a(ftgzip.c.o): in function `FT_Stream_OpenGzip':
ftgzip.c:(.text+0x6b1): undefined reference to `inflateInit2_'
/usr/bin/ld: ftgzip.c:(.text+0x85f): undefined reference to `inflateEnd'
/usr/bin/ld: /home/ilmu011/Desktop/vcpkg/installed/x64-linux/lib/libfreetype.a(ftgzip.c.o): in function `FT_Gzip_Uncompress':
ftgzip.c:(.text+0x984): undefined reference to `inflateInit2_'
/usr/bin/ld: ftgzip.c:(.text+0x998): undefined reference to `inflate'
/usr/bin/ld: ftgzip.c:(.text+0x9a7): undefined reference to `inflateEnd'
/usr/bin/ld: ftgzip.c:(.text+0xa1c): undefined reference to `inflateEnd'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/CylinderExample.dir/build.make:145: CylinderExample] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/CylinderExample.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
When I try to do this with the built-from-source installation (9.1), nothing changes. make simply does nothing. But it looks like, in that case, cmake doesn’t even recognize vtk at all. I tried leaving out the vtk directory to the installation and no errors where thrown. I begin to suspect that cmake doesn’t even find vtk in the first place and weirdly doesn’t even throw any error messages
to my cmake file and also tried it with the command line option, but the missing module error still ocurs (in the vcpkg installation; the source installation stil seems to be unrecognized for whatever reason)
To get rid of the “undefined reference” errors, try removing vtkRenderingFreeType from the COMPONENTS as well. I say this because all of the warnings mention libfreetype.a.
There must be something wrong with the vcpkg for VTK, because if the package was correct, then vtkRenderingFreeType would automatically link to libpng and to all the other libraries that libfreetype needs.
Please note that I don’t have any experience with vcpkg, so my answers might not be correct.
Edit: another possibility is that you have more than one libfreetype installed on your system, and cmake is finding the wrong one. For example, maybe one libfreetype was installed from a ubuntu package and another from vcpkg.
Fine, let’s say the vcpkg version is broken, I still don’t understand how cmake seems to completely ignore the source installation despite me providing the installation directory. It doesn’t even throw error messages, it simply does nothing.
I built the source installation with the ccmake command, are there any settings I had to adjust? For example, CMAKE_BUILD_TYPE is set to “Debug”, shouldn’t that be Release? Is that even important? I have no idea how to make this work. I followed every step of the installation steps prvided here: https://gitlab.kitware.com/vtk/vtk/-/blob/master/Documentation/dev/build.md
At this point I am just trying to get a working VTK installation.
I just checked libfreetype installations, it seems to be the case that there is both an apt installation and a vcpkg one. But which is the right one and how do I make it so that the right one is used?
Regarding the source installation: I just checked the CMakeCache.txt in the build folder. I found this entry:
//The directory containing a CMake configuration file for VTK.
VTK_DIR:PATH=VTK_DIR-NOTFOUND
The directory I specified isn’t applied. Am I giving cmake the wrong directory? I just assumed (following the build directions) I had to point to “vtk/build”. The instructions say
If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:
The error log is because VTK wasn’t built, so all of the library targets that cmake needs are missing.
For now, I suggest going back to the vcpkg vtk, because if that works, it will be the simplest way forward.
The problem there was libfreetype and the missing symbols, so try re-configuring your example against the vcpkg vtk, and then look through the generated CMakeCache.txt for freetype and other system libraries, and make sure they point to the apt-installed libraries. E.g.:
It’s fine if the “DEBUG” versions of these libraries are “NOTFOUND”. I also recommend setting CMAKE_BUILD_TYPE to Release unless you specifically intend to run the example in a debugger.
Also, is it really more complicated to just build the VTK from source?
The instructions used ccmake for this step, but I’m not familiar with that tool and probably missed some steps
I did check the Cache and it turns out it DOES point to the vcpkg installation. However, isn’t this the point? I thought vcpkg handled dependencies like these automatically. How is it possible that this version is incompatible with vtk?