Creating a DLL with VTK throws syntax error in vtkBuffer - c++

I created a DLL project by following this Microsoft tutorial, which works fine.
Now, I tried to modify the .h and .cpp files and include a vtkPolydata as follows.
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;
}
Then, it throws the following 15 errors in vtkBuffer:
> 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
How can I fix this?
Note that I used vcpkg to install the VTK package, and I didn't encounter any problem/error with VTK in my console application project.

I found the answer.
If you follow the tutorial above, you will find framework.h file. The framework.h includes windows.h which has macros for min. This macros causes the error.
To fix this, add #define NOMINMAX before #include<windows.h>.
More explanation of the error can be found here

Related

Why typedef throws declaration error in Qt5?

//nothing above
#include <QComboBox>
#include <QCheckBox>
typedef QList<QList<QComboBox*>*> ComboLists;
typedef is used right after #include area so it cannot be connected with other ';' token errors
this leads to declaration error with ';'
C:\Users\Admin\Documents\XML_TV\xmlmessage.h:18: error: invalid declarator before ';' token
In file included from ..\XML_TV\widget.h:8,
from ..\XML_TV\widget.cpp:1:
..\XML_TV\xmlmessage.h:18:45: error: invalid declarator before ';' token
18 | typedef QList<QList<QComboBox*>*> ComboLists;
| ^
Cleaning project doesn't helping at all. One day before this error everything worked perfectly.

including freetype-gl.h causes wglew errors

I've integrated all the needed files to use freetype-gl.hdirectly into my OpenGL project, but when I try to build the program, I receive 262 errors complaining aboutwglew.h. A sample of the errors:
error C2143: syntax error : missing ')' before '*' c:\bar\includes\glew110\include\gl\wglew.h 113 1 Foo
error C2143: syntax error : missing ';' before '*' c:\bar\glew110\include\gl\wglew.h 113 1 Foo
error C2059: syntax error : ')' c:\bar\includes\glew110\include\gl\wglew.h 113 1 Foo
error C2065: 'HDC' : undeclared identifier c:\bar\glew110\include\gl\wglew.h 113 1 Foo
error C2146: syntax error : missing ')' before identifier 'hDC' c:\bar\includes\glew110\include\gl\wglew.h 113 1 Foo
And in my class, just this header causes the problem with wglew.h:
#include "freetype-gl.h" // causes all the errors
This solution solved a wglew error for me, not sure if it's the same problem.
Try adding the wglew.h include line to the same file as your other include line for freetype-gl.h, and in this order:
#include <Windows.h> // maybe not needed
#define GLEW_STATIC // maybe not needed
#include "GL/glew.h"
#include "GL/wglew.h"
#include "freetype-gl.h"
// other includes below

How to find the "real" error?

I am having an enormous amount of errors showing up in the error list of the program, but none of the ones listed seem to be "real" errors. Some of the lines are red and then when I go to highlight over them the error disappears. I just can't seem to find where my error really is. What is the best process to go through to find my mistake?
Below is the error list in case that is helpful.
Error 38 error C1004: unexpected end-of-file found 85
Error 68 error C1004: unexpected end-of-file found 42
Error 63 error C1903: unable to recover from previous error(s); stopping compilation 72
Error 66 error C2059: syntax error : ')' 42
Error 2 error C2059: syntax error : '>' 80
Error 40 error C2059: syntax error : '>' 80
Error 65 error C2059: syntax error : '>' 42
Error 20 error C2065: '_Ptr_cerr' : undeclared identifier 27
Error 16 error C2065: '_Ptr_cin' : undeclared identifier 25
Error 22 error C2065: '_Ptr_clog' : undeclared identifier 28
Error 18 error C2065: '_Ptr_cout' : undeclared identifier 26
Error 28 error C2065: '_Ptr_wcerr' : undeclared identifier 32
Error 24 error C2065: '_Ptr_wcin' : undeclared identifier 30
Error 30 error C2065: '_Ptr_wclog' : undeclared identifier 33
Error 26 error C2065: '_Ptr_wcout' : undeclared identifier 31
Error 4 error C2065: 'faction' : undeclared identifier 84
Error 42 error C2065: 'faction' : undeclared identifier 84
Error 64 error C2065: 'Faction' : undeclared identifier 42
Error 13 error C2065: 'socialite' : undeclared identifier 100
Error 51 error C2065: 'socialite' : undeclared identifier 100
Error 1 error C2065: 'Socialite' : undeclared identifier 80
Error 12 error C2065: 'Socialite' : undeclared identifier 100
Error 39 error C2065: 'Socialite' : undeclared identifier 80
Error 50 error C2065: 'Socialite' : undeclared identifier 100
Error 8 error C2065: 'textWriter' : undeclared identifier 82
Error 46 error C2065: 'textWriter' : undeclared identifier 82
Error 6 error C2143: syntax error : missing ',' before ')' 84
Error 10 error C2143: syntax error : missing ',' before ')' 82
Error 14 error C2143: syntax error : missing ',' before ')' 100
Error 44 error C2143: syntax error : missing ',' before ')' 84
Error 48 error C2143: syntax error : missing ',' before ')' 82
Error 52 error C2143: syntax error : missing ',' before ')' 100
Error 17 error C2143: syntax error : missing ',' before ';' 25
Error 19 error C2143: syntax error : missing ',' before ';' 26
Error 21 error C2143: syntax error : missing ',' before ';' 27
Error 23 error C2143: syntax error : missing ',' before ';' 28
Error 25 error C2143: syntax error : missing ',' before ';' 30
Error 27 error C2143: syntax error : missing ',' before ';' 31
Error 29 error C2143: syntax error : missing ',' before ';' 32
Error 31 error C2143: syntax error : missing ',' before ';' 33
Error 7 error C2143: syntax error : missing ';' before '{' 32
Error 15 error C2143: syntax error : missing ';' before '{' 10
Error 32 error C2143: syntax error : missing ';' before '{' 36
Error 35 error C2143: syntax error : missing ';' before '{' 27
Error 45 error C2143: syntax error : missing ';' before '{' 32
Error 54 error C2143: syntax error : missing ';' before '{' 34
Error 57 error C2143: syntax error : missing ';' before '{' 48
Error 60 error C2143: syntax error : missing ';' before '{' 61
Error 3 error C2143: syntax error : missing ';' before '}' 82
Error 11 error C2143: syntax error : missing ';' before '}' 98
Error 33 error C2143: syntax error : missing ';' before '}' 42
Error 34 error C2143: syntax error : missing ';' before '}' 45
Error 36 error C2143: syntax error : missing ';' before '}' 83
Error 37 error C2143: syntax error : missing ';' before '}' 85
Error 41 error C2143: syntax error : missing ';' before '}' 82
Error 49 error C2143: syntax error : missing ';' before '}' 98
Error 55 error C2143: syntax error : missing ';' before '}' 43
Error 58 error C2143: syntax error : missing ';' before '}' 57
Error 61 error C2143: syntax error : missing ';' before '}' 69
Error 67 error C2143: syntax error : missing ';' before '}' 42
Error 5 error C2275: 'Faction' : illegal use of this type as an expression 84
Error 43 error C2275: 'Faction' : illegal use of this type as an expression 84
Error 9 error C2275: 'std::ofstream' : illegal use of this type as an expression 82
Error 47 error C2275: 'std::ofstream' : illegal use of this type as an expression 82
Error 53 error C2653: 'Socialite' : is not a class or namespace name 33
Error 56 error C2653: 'Socialite' : is not a class or namespace name 46
Error 59 error C2653: 'Socialite' : is not a class or namespace name 60
Error 62 error C2653: 'Socialite' : is not a class or namespace name 72
Probably a missing ; after the closing } of a class / struct. Could you post some code?
UPDATE: The code compiles now on my gcc. The problem I found is that you have a circular dependency between your classes. So solve this, forward declare some of them in the headers. I added class Faction; before class Socialite in Socialite.h and class Socialite; before class Faction in Faction.h.
Unexpected end of file is usually that you are missing a closing "something", such as a bracket } or parenthesis )
It's either a missing #endif or a ; at the end of a type definition or possibly a missing } at the end of a function.
Start with the first error reported. Often it's the cause of a lot of the subsequent problems because the first error causes the parser to be out of sync with the rest of the code.
In C++, long cascades of errors are often caused by an undeclared type (did you forget an include file?) or by a missing ; after a class or struct definition.
Consider:
Foobar fb; // Declare an instance of Foobar.
If Foobar hasn't been declared yet (perhaps because you forgot to include "foobar.h"), then the compiler might think you're trying to declare a variable named Foobar with a default type of int. From there, it sees the fb and gets all confused.
Or consider:
struct Foobar {
int x;
int y;
}
int blah = 0;
Without the ; after the struct definition, the parser thinks you're trying to declare an instance of Foobar named int, which isn't allowed since int is a reserved keyword. And everything after that looks like gobbledegook to the compiler.
One trick is to temporarily #if 0-out all the code after the line with the first reported error, as that will reduce the noise until you isolate the original problem.
If you look at the "Error List" window (View > Error List) it can be really hard to figure out where the errors originate. Luckily, there's another way:
Open the "Output" window (Debug > Windows > Output)
Compile and build
Start at the top of the "Output" window and work your way down the compiler/linker output text until you come to the first line that says "error"
This will usually lead you right to the problem.

C++ Header file - syntax problems

I have some errors in my header file, which I don't know how to fix because I am fairly new to C++.
Here is the code of the header file:
#pragma once
typedef unsigned int uint;
class DCEncryption
{
public:
static char* manageData(char*, char*, uint);
private:
static int max(int, int);
static uint leftRotate(uint, int);
};
And here are the errors:
- dcencryption.h(12): error C2062: type 'int' unexpected
- dcencryption.h(12): error C2334: unexpected token(s) preceding ':'; skipping apparent function body
- dcencryption.h(12): error C2760: syntax error : expected '{' not ';'
- dcencryption.h(13): error C2144: syntax error : 'uint' should be preceded by '}'
- dcencryption.h(13): error C2143: syntax error : missing ')' before ';'
- dcencryption.h(13): error C2059: syntax error : ')'
- dcencryption.h(13): error C2143: syntax error : missing ';' before ')'
- dcencryption.h(13): error C2238: unexpected token(s) preceding ';'
You are probably on Windows and you have included windef.h directly or indirectly (through windows.h, maybe) from your main .cpp file before including the shown file.
It so happens that max is a macro defined in windef.h that does not expand nicely in your context.
This can quite easily happen on some other platforms as well.

Testing function with BOOST.Test

I have a fnc:
template<class T, T constraint>
inline void CheckSize(const T& value)
{
if (value < constraint)
{
throw BadSize_ex(value);
}
}
but I cannot test it with Boost. What I'm doing is this ():
BOOST_REQUIRE_THROW(CheckSize<int,2>(1),std::BadSize_ex);
Where is the problem?
but I'm getting lots of miningless errors of type ',' missing before ';'.
Errors (Some of them but all of them are from this ball park)
Error 5 error C2143: syntax error : missing ',' before ';'
Error 6 error C2143: syntax error : missing '>' before '{'
Error 7 error C2143: syntax error : missing ';' before '{'
Error 8 error C2143: syntax error : missing ',' before ')'
Error 45 error C2143: syntax error : missing ';' before '}'
Error 46 error C1004: unexpected end-of-file found
It is the comma between template parameters. Try with additional paranthesis:
BOOST_REQUIRE_THROW( (CheckSize<int,2>(1)),std::BadSize_ex);
You need to use BOOST_PP_COMMA() in place of , if you want to pass commas within parameters instead of to delimit parameters. This is basically because the preprocessor can't recognize template parameter delimiting over macro parameter delimiting.