Problems in compiling VTK with cmake: solutions to error configuration process, project files may be invalid

After setting up the basic VTK environment, the learning process follows. But I had a bunch of problems in the first example. Here’s how to solve them. Fill in a bunch of holes first.

1. Problem introduction
I follow: Dongling VTK tutorial series navigation learning.
>
>
>
>
>
>
>
>
>
The first is the cmake code:

cmake_minimum_required(VERSION2.8)

project(TestVTKInstall)

find_package(VTKREQUIRED)

include(${VTK_USE_FILE})

add_executable(${PROJECT_NAME}TestVTKInstall.cpp)

target_link_libraries(${PROJECT_NAME}vtkRendering vtkCommon)


Then the CPP code:

#include <vtkRenderWindow.h>
#include <vtkSmartPointer.h>

int main()
{
	vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
	renWin->Render();
	std::cin.get();
	return 0;
}

ror configuration process, project files may be invalid.>r> error configuration process, project files may be invalid
2. Problem solving:
Error Configuration Process: The Project Files may be invalid method did not work. Here’s a little bit about this approach.
2.1 No use of CMAKE to select the version of VS on the corresponding machine.

When generating the corresponding VS solution with the CMAKE configuration, you need to correspond to the correct VS version. This is the same version that you used when installing VTK.
2.2 Previous error cache is not cleaned
|
click on the top left corner of the file - & gt; Delete cathe
to clear the cache.
2. 3 cmake list programming problems
Following the above description did not solve our problem, so we had to continue to Google. We saw us have similar questions on several StackOverflow posts.

    VTK + Cmake -> USE_VTK_RENDERING erroCMake error: ‘Target is not built by this project’ Cmake link liabray target link errorCMake OpenCV Cannot Specify link Libraries

According to the above, compared with our CMMakelists code, we tried one code after another, and finally found a very hidden error, that is, we must pay attention to the space in CMMakelists!!

To be specific,

    is the first line: rsion a> code>2.8e> have a space> The third line: VTKd r>red has a s> on line 9, testvtkinstal>cpp has a space on line> In line 11, we change the previous vtkRendering vtkCommon $>tk_libraries} with a>e before. There is nothing wrong with cmake, though, if you simply add a space. However, when VS is compiled later, the following error will occur, so it will be fine to fix it.

Finally, the cmMakelists.txt code:

cmake_minimum_required(VERSION 2.8)

project(TestVTKInstall)

find_package(VTK REQUIRED)

include(${VTK_USE_FILE})

add_executable(${PROJECT_NAME} TestVTKInstall.cpp)

target_link_libraries(${PROJECT_NAME} ${VTK_LIBRARIES})

3. Run in VS
After cmake has no errors, we configure, then generate. Open VS2017 as an administrator. Open the file we compiled.
> compile l_build >>ck on F7 or build it. If there are no errors, right-click TestVTKInstall and set it as a startup item, then click F5, or run to get the correct results.

Over

Just solve problems one by one.

Read More: