4.1 Debug版编译错误(error LNK1169: one or more multiply defined symbols found);
错误信息:
vtkCommonCore-9.3d.lib(vtkCommonCore-9.3d.dll) : error LNK2005: "public: __cdecl vtkConstantImplicitBackend<unsigned __int64>::vtkConstantImplicitBackend<unsigned __int64>(unsigned __int64)" (??0?$vtkConstantImplicitBackend@_K@@QEAA@_K@Z) already defined in vtkToImplicitRamerDouglasPeuckerStrategy.cxx.obj
Creating library lib\Debug\vtkFiltersReduction-9.3d.lib and object lib\Debug\vtkFiltersReduction-9.3d.exp
bin\Debug\vtkFiltersReduction-9.3d.dll : fatal error LNK1169: one or more multiply defined symbols found
解决方法:
定位源文件,并修改代码:
VTK-9.3.0/Common/Core/vtkConstantImplicitBackend.h
修改前:
struct VTKCOMMONCORE_EXPORT vtkConstantImplicitBackend final
修改后:
struct vtkConstantImplicitBackend final
#include<vtkAutoInit.h>#include<vtkOutputWindow.h>#include<vtkActor.h>#include<vtkCamera.h>#include<vtkCylinderSource.h>#include<vtkNamedColors.h>#include<vtkNew.h>#include<vtkPolyDataMapper.h>#include<vtkProperty.h>#include<vtkRenderWindow.h>#include<vtkRenderWindowInteractor.h>#include<vtkRenderer.h>#include<array>VTK_MODULE_INIT(vtkRenderingOpenGL2)VTK_MODULE_INIT(vtkInteractionStyle)intmain(int,char*[]){
vtkOutputWindow::SetGlobalWarningDisplay(0);
vtkNew<vtkNamedColors> colors;// Set the background color.
std::array<unsignedchar,4> bkg{{26,51,102,255}};
colors->SetColor("BkgColor", bkg.data());// This creates a polygonal cylinder model with eight circumferential facets// (i.e, in practice an octagonal prism).
vtkNew<vtkCylinderSource> cylinder;
cylinder->SetResolution(8);// The mapper is responsible for pushing the geometry into the graphics// library. It may also do color mapping, if scalars or other attributes are// defined.
vtkNew<vtkPolyDataMapper> cylinderMapper;
cylinderMapper->SetInputConnection(cylinder->GetOutputPort());// The actor is a grouping mechanism: besides the geometry (mapper), it// also has a property, transformation matrix, and/or texture map.// Here we set its color and rotate it around the X and Y axes.
vtkNew<vtkActor> cylinderActor;
cylinderActor->SetMapper(cylinderMapper);
cylinderActor->GetProperty()->SetColor(
colors->GetColor4d("Tomato").GetData());
cylinderActor->RotateX(30.0);
cylinderActor->RotateY(-45.0);// The renderer generates the image// which is then displayed on the render window.// It can be thought of as a scene to which the actor is added
vtkNew<vtkRenderer> renderer;
renderer->AddActor(cylinderActor);
renderer->SetBackground(colors->GetColor3d("BkgColor").GetData());// Zoom in a little by accessing the camera and invoking its "Zoom" method.
renderer->ResetCamera();
renderer->GetActiveCamera()->Zoom(1.5);// The render window is the actual GUI window// that appears on the computer screen
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetSize(300,300);
renderWindow->AddRenderer(renderer);
renderWindow->SetWindowName("Cylinder");// The render window interactor captures mouse events// and will perform appropriate camera or actor manipulation// depending on the nature of the events.
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow);// This starts the event loop and as a side effect causes an initial render.
renderWindow->Render();
renderWindowInteractor->Start();return EXIT_SUCCESS;}