c++ 使用VTK创建DLL会在vtkBuffer中引发语法错误

4si2a6ki  于 2023-01-22  发布在  其他
关注(0)|答案(1)|浏览(212)

我按照这个Microsoft tutorial创建了一个DLL项目,它运行良好。
现在,我尝试修改. h和. cpp文件,并包含一个vtkPolydata,如下所示。
SurfaceGeneration.h

#pragma once

#ifdef SURFACEGENERATION_EXPORTS
#define SURFACEGENERATION_API __declspec(dllexport)
#else
#define SURFACEGENERATION_API __declspec(dllimport)
#endif

// Load the playdoh model and the polylines text file
extern "C" SURFACEGENERATION_API void sg_init(
    const std::string data_folder, const std::string _playdoh_filename, const std::string _polyline_filename);

// Apply the surface generation algorithm to the playdoh model based on the polylines in the text file.
extern "C" SURFACEGENERATION_API bool sg_execute();

SurfaceGeneration.cpp

#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier
#include <utility>
#include <limits.h>
#include <iostream>
#include <string>

#include "SurfaceGeneration.h"
#include <vtk-9.0/vtkPolyData.h>

// DLL internal state variables: none

void sg_init(const std::string data_folder, const std::string _playdoh_filename, const std::string _polyline_filename)
{
}

// Returns true on success, false on failure.
bool sg_execute()
{

    return true;
}

然后,它在vtkBuffer中抛出以下15个错误:

> Error C2589   '(': illegal token on right side of
> '::'  SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  222 
> Error C2065   'newArray': undeclared
> identifier    SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  222 
> Error C2065   'newArray': undeclared
> identifier    SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  224 
> Error C2760   syntax error: ')' was unexpected here; expected
> ';'   SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  222 
> Error C2760   syntax error: ')' was unexpected here; expected
> ';'   SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  222 
> Error C2760   syntax error: ')' was unexpected here; expected
> '}'   SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  222 
> Error C2760   syntax error: ':' was unexpected here; expected
> ';'   SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  222 
> Error C3878   syntax error: unexpected token '(' following
> 'expression'  SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  222 
> Error C3878   syntax error: unexpected token ')' following
> 'compound_statement'  SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  222 
> Error C3878   syntax error: unexpected token ')' following
> 'expression_statement'    SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  222 
> Error C3878   syntax error: unexpected token ')' following
> 'expression_statement'    SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  222 
> Error C3878   syntax error: unexpected token ')' following
> 'selection_statement' SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  222 
> Error C3878   syntax error: unexpected token ')' following
> 'statement'   SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  222 
> Error C3878   syntax error: unexpected token ')' following
> 'statement_seq'   SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  222 
> Error C3878   syntax error: unexpected token ':' following
> 'expression_statement'    SurfaceGenerationDLL    C:\vcpkg\installed\x64-windows\include\vtk-9.0\vtkBuffer.h  222

我该怎么补救呢?
注意,我使用vcpkg安装了VTK包,并且在控制台应用程序项目中没有遇到任何VTK问题/错误。

62o28rlo

62o28rlo1#

我找到答案了。
如果你按照上面的教程,你会发现framework.h文件。framework.h包括windows.h,其中有min的宏。这个宏导致错误。
要解决此问题,请在#include<windows.h>之前添加#define NOMINMAX
有关该错误的更多说明,请参见here

相关问题