Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Compilation issues with Cxx examples #246

Open
dbworth opened this issue Nov 17, 2018 · 0 comments
Open

Fix: Compilation issues with Cxx examples #246

dbworth opened this issue Nov 17, 2018 · 0 comments

Comments

@dbworth
Copy link

dbworth commented Nov 17, 2018

Hi,
This issue is to address problems with compiling the Cxx examples on Linux.
I opened a PR #245

Background:
As a Developer I want to contribute to this project.
When following the instructions here:
https://lorensen.github.io/VTKExamples/site/Instructions/ForDevelopers/
I found that building all the examples does not succeed, using the default CMake configuration, to varying degrees depending on what version of VTK you are using.

How to reproduce:

  • Install Ubuntu 16.04
  • Use VTK 6.2 from Ubuntu repo, or compile VTK 6.2 to 8.1.0 from source
  • Use default CMake config, including without C++11
  • Complete all steps to "7. Build the VTKExamples", which is to runmake
  • The compilation will not finish
    .

Issues:
I found that many of the Cxx examples would not compile "out of the box" for me, due to:

  1. Missing a header include
  2. Need a specific version of VTK
  3. Need C++11

.

Fixes made in this PR:

1. Missing headers
These were added.

2. Need specific version of VTK
For these examples, the missing guard was added so the example only compiles if you have the minimum version.
Either using the macro:

Requires_Version()

or

if(NOT ${VTK_VERSION} VERSION_EQUAL "7.0.0")
endif()

3. Need C++ 11
Whilst we could debate this, the VTK documentation says that the C++03 standard is used: https://www.vtk.org/Wiki/VTK/Wrapping_C%2B%2B11_Code

Most of the examples do not require C++11, but a few do, which breaks the build.

Therefore, where possible, example code was changed to follow the older standard.
e.g. by removing auto
If the change was not easy, because a new feature is used or affects too many lines, a guard was added so the example will only compile if the user has enabled C++11.

Using either a new macro:

Requires_CxxVersion()

or

if (USING_CPP11)
endif()

I added a script CheckCxxStandard.cmake that attempts to handle that users can do either:
Set the "-std=c++11" flag, possibly via some IDE
OR use the newer CMake command : set(CMAKE_CXX_STANDARD 11)

The script can detect the flags "std=c++11" or "std=gnu++11"
and is compatible if the user enables set(CMAKE_CXX_STANDARD 11) or set(CMAKE_CXX_STANDARD 14)

.

Tests:
These changes were tested with multiple versions of VTK using:

  • Ubuntu 16.04
  • CXX compiler GNU 5.4.0
  • the default CMake options for VTK, except for enabling Qt5 starting from VTK 7.1.0

Qt4
VTK 6.2.0
VTK 6.2.0 C++11
VTK 7.0.0
VTK 7.0.0 C++11
VTK 7.1.0

Qt5
VTK 7.1.0 C++11
VTK 8.0.0
VTK 8.0.0
VTK 8.1.0
VTK 8.1.0 C++11

.

Hopefully this work will help other users. Your feedback is welcome.

.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant