error C2381: 'exit' : redefinition; __declspec(noreturn) differs

Hi, could someone please take a look at my code? I have this error: "redefinition; __declspec(noreturn) differs" and I don't know how should I solve it. Please help me. Thank you!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
  #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <GL/glut.h>
#include "loop.h"
#include <windows.h>

HWND ghwndEdit;
HWND hwnd;
LPSTR file;

void screen_keyboard(unsigned char key, int x, int y) {
	char* name = 0;
	Vertex* vertex;
	long lines = 0;
	
	switch (key) {
		case 'W':
		case 'w':
			wire = !wire;
			break;
		case 'A':
		case 'a':
			refine(we);
			unitize(we);
			facetNormals(we);
			printf("%d Faces.\n", faceCount(we));
			break;
		case 'S':
		case 's':
			subdivide(we);
			unitize(we);
			facetNormals(we);
			printf("%d Faces.\n", faceCount(we));
			break;
		case 'L':
		case 'l':
			subdivide(we); 
			refine(we);
			unitize(we);
			facetNormals(we);
			printf("%d Faces.\n", faceCount(we));
			break;
		case 'B':
		case 'b':
			subdivideButt(we);
			refine(we);
			unitize(we);
			facetNormals(we);
			break;
		case 'D':
		case 'd':
			name = "data/drum.obj";
			break;
		case 'Z':
		case 'z':
			name = "data/ball.obj";
			break;
		case 'H':
		case 'h':
			name = "data/sphere.obj";
			break;
		case 'E':
		case 'e':
			name = "data/equilateraltri.obj";
				break;
		case 'U':
		case 'u':
			name = "data/cube.obj";
			break;
		case 'P':
		case 'p':
			name = "data/prism.obj";
			break;
		case 'C':
		case 'c':
			name = "data/cylinder.obj";
			break;
		case 'T':
		case 't':
			name = "data/isoscelestri.obj";
			break;
		case 'O':
		case 'o':
			name = filename;
			break;
		case 'I':
		case 'i':
			//Import shape
			//WinMain(hInstance, hPrevInstance,lpCmdLine, nCmdShow);
			//WndProc(hwnd, msg, wParam, lParam);
			void OpenDialog(HWND hwnd); {
				OPENFILENAME ofn;
				TCHAR szFile[MAX_PATH];
				
				ZeroMemory(&ofn, sizeof(ofn));
				ofn.lStructSize = sizeof(ofn);
				ofn.lpstrFile = szFile;
				ofn.lpstrFile[0] = '\0';
				ofn.hwndOwner = hwnd;
				ofn.nMaxFile = sizeof(szFile);
				ofn.lpstrFilter = TEXT("All files(*.*)\0*.*\0");
				ofn.nFilterIndex = 1;
				ofn.lpstrInitialDir = NULL;
				ofn.lpstrFileTitle = NULL;
				ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
				
				if(GetOpenFileName(&ofn))
					LoadFile(ofn.lpstrFile);
			};
			
			void LoadFile(LPSTR file);
			{
				HANDLE hFile;
				DWORD dwSize;
				DWORD dw;
				
				LPBYTE lpBuffer = NULL;
				
				hFile = CreateFile(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
				dwSize = GetFileSize(hFile, NULL);
				lpBuffer = (LPBYTE) HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, dwSize + 1);
				ReadFile(hFile, (LPWSTR)lpBuffer, dwSize, &dw, NULL);
				CloseHandle(hFile);
				lpBuffer[dwSize] = 0;
				SetWindowText(ghwndEdit, (LPSTR) lpBuffer);
				HeapFree(GetProcessHeap(), 0, lpBuffer);
			}
			break;	
		case 'X':
		case 'x':
			lines = writeOBJ(we, "output.obj");
			printf("Wrote output.obj (%d lines)\n", lines);
			break;
		case 'V':
		case 'v':
			verify(we);
			break;
		case '1':
			vertex =	we->vertices;
			while (vertex) {
				vertex->newpoint = GL_FALSE;
				vertex = vertex->next;
			}
			firstDivision(we->faces);
			unitize(we);
			facetNormals(we);
			printf("----- First Pass -----\n");
			printf("%d Vertices.\n", vertexCount(we));
			printf("%d Faces.\n\n", faceCount(we));			
			break;
		case 'Q':
		case 'q':
			exit(1);
			break;	
		case 'R':
		case 'r':
			break;
	}
    
	if (name) {
		if (we) free(we);
		we = readOBJ(name); 
		if (!we) exit(0);
		unitize(we);
		facetNormals(we);
	}
    
	redisplay_all();
}
Searching the error message seems o sugest you should include GL/glut.h last.
IS loop.h your creation? If so can you post it?
you cannot define functions within a function.

line 94 and 114 do not define a function you can call (like on line 111). It defines only prototypes.
Hi Peter87, tried to move #include <GL/glut.h> to the last but the error still appear. Thanks!
Hi tipaye, below is the code from loop.h:


#include <GL/glut.h>
#include <stdio.h>
#include <memory.h>
#include <windows.h>

#pragma warning (disable:4018)
#pragma warning (disable:4101)

#ifndef M_PI
#define M_PI 3.14159265f
#endif



class Triangle {
public :
	Triangle(){memset(this,0,sizeof(Triangle));}
	GLuint verts[3];
} ;

class Vertex {
public :
	Vertex(){memset(this,0,sizeof(Vertex)) ;}
	GLfloat x, y, z;
	GLboolean newpoint;
	class Vertex* averaged; /* used for subdivision */
	class Vertex* next; /* no geometric meaning - just a list */
} ;

class Edge {
public :
	Edge(){memset(this,0,sizeof(Edge)) ;}
	class Vertex* head;
	class Vertex* tail;
	
	class Edge* next;
	class Edge* prev;
	class Edge* twin;

	class Face* left;
	class Face* right;
} ;

class Face {
public :
	Face(){	memset(this,0,sizeof(Face)) ;}
	class Edge* edge;

	class Vertex* normal;
	
	class Face* next; /* no geometric meaning - just a list */

} ;

class WingedEdge {
public :
	WingedEdge(){memset(this,0,sizeof(WingedEdge)) ;}
	class Face* faces;
	class Vertex* vertices;
	/* edges are already uniquely ordered by the faces */
} ;

class Model {
public :
	Model(){memset(this,0,sizeof(Model)) ;}
	GLuint numVertices;
	GLuint numFaces;

	Vertex* position;
} ;

long writeOBJ(WingedEdge* we, char* filename);
WingedEdge* readOBJ(char* filename);
GLvoid firstPass(Model* model, FILE* file);
WingedEdge* secondPass(Model* model, FILE* file);
GLfloat unitize(WingedEdge* we);
GLvoid facetNormals(WingedEdge* we);
GLvoid vertexNormals(WingedEdge* we);
GLfloat sabs(GLfloat f);
GLfloat smax(GLfloat a, GLfloat b);
GLfloat sdot(Vertex* u, Vertex* v);
Vertex* scross(Vertex* u, Vertex* v);
GLvoid snormalize(Vertex* v);
GLboolean sequal(Vertex* u, Vertex* v, GLfloat epsilon);
GLvoid subdivide(WingedEdge* we);
GLvoid subdivideButt(WingedEdge * we);
GLvoid firstDivision(Face* face);
GLvoid secondDivision(Face* face);
GLvoid secondDivisionButterflyJoin(Face* face);
GLvoid refine(WingedEdge* we);
GLvoid refineButt(WingedEdge we);
GLvoid verify(WingedEdge* we);
Vertex* midpoint(Vertex* v1, Vertex* v2);
long faceCount(WingedEdge* we);
long vertexCount(WingedEdge* we);
//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow);
//LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
void OpenDialog(HWND hwnd);
void LoadFile(LPSTR file);

void wireObject(WingedEdge* we) ;
void flatObject(WingedEdge* we) ;
That didn't help as much as I thought, but you definitely have a problem as highlighted by coder777

I've changed things round a bit, to what I think you're after.

I placed the declaration/definition of the functions OpenDialog and LoadFile towards the beginning of the file in a valid proper scope.

I've called the functions in your switch statement

Since you already have hwnd, and file defined globally, I took them out of the function signatures, to prevent a confusing namespace clash.

It may be that you prefer to keep them in and not define them globally, but I picked what I felt was the worst alternative, just so you consider it a bit more. Generally, I don't do Windows, so I haven't compiled any of this nor do I even pretend to understand what's happening. I just corrected what I thought was wrong. See below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
 #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <GL/glut.h>
#include "loop.h"
#include <windows.h>

HWND ghwndEdit;
HWND hwnd;
LPSTR file;

void OpenDialog(/* HWND hwnd */); 
{
	OPENFILENAME ofn;
	TCHAR szFile[MAX_PATH];
	
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.lpstrFile = szFile;
	ofn.lpstrFile[0] = '\0';
	ofn.hwndOwner = hwnd;
	ofn.nMaxFile = sizeof(szFile);
	ofn.lpstrFilter = TEXT("All files(*.*)\0*.*\0");
	ofn.nFilterIndex = 1;
	ofn.lpstrInitialDir = NULL;
	ofn.lpstrFileTitle = NULL;
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
	
	if(GetOpenFileName(&ofn))
		LoadFile(ofn.lpstrFile);
};

void LoadFile(/* LPSTR file */);
{
	HANDLE hFile;
	DWORD dwSize;
	DWORD dw;
	
	LPBYTE lpBuffer = NULL;
	
	hFile = CreateFile(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
	dwSize = GetFileSize(hFile, NULL);
	lpBuffer = (LPBYTE) HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, dwSize + 1);
	ReadFile(hFile, (LPWSTR)lpBuffer, dwSize, &dw, NULL);
	CloseHandle(hFile);
	lpBuffer[dwSize] = 0;
	SetWindowText(ghwndEdit, (LPSTR) lpBuffer);
	HeapFree(GetProcessHeap(), 0, lpBuffer);
}

void screen_keyboard(unsigned char key, int x, int y) {
	char* name = 0;
	Vertex* vertex;
	long lines = 0;
	
	switch (key) {
		case 'W':
		case 'w':
			wire = !wire;
			break;
		case 'A':
		case 'a':
			refine(we);
			unitize(we);
			facetNormals(we);
			printf("%d Faces.\n", faceCount(we));
			break;
		case 'S':
		case 's':
			subdivide(we);
			unitize(we);
			facetNormals(we);
			printf("%d Faces.\n", faceCount(we));
			break;
		case 'L':
		case 'l':
			subdivide(we); 
			refine(we);
			unitize(we);
			facetNormals(we);
			printf("%d Faces.\n", faceCount(we));
			break;
		case 'B':
		case 'b':
			subdivideButt(we);
			refine(we);
			unitize(we);
			facetNormals(we);
			break;
		case 'D':
		case 'd':
			name = "data/drum.obj";
			break;
		case 'Z':
		case 'z':
			name = "data/ball.obj";
			break;
		case 'H':
		case 'h':
			name = "data/sphere.obj";
			break;
		case 'E':
		case 'e':
			name = "data/equilateraltri.obj";
				break;
		case 'U':
		case 'u':
			name = "data/cube.obj";
			break;
		case 'P':
		case 'p':
			name = "data/prism.obj";
			break;
		case 'C':
		case 'c':
			name = "data/cylinder.obj";
			break;
		case 'T':
		case 't':
			name = "data/isoscelestri.obj";
			break;
		case 'O':
		case 'o':
			name = filename;
			break;
		case 'I':
		case 'i':
			//Import shape
			//WinMain(hInstance, hPrevInstance,lpCmdLine, nCmdShow);
			//WndProc(hwnd, msg, wParam, lParam);
			OpenDialog();
			LoadFile();
			break;	
		case 'X':
		case 'x':
			lines = writeOBJ(we, "output.obj");
			printf("Wrote output.obj (%d lines)\n", lines);
			break;
		case 'V':
		case 'v':
			verify(we);
			break;
		case '1':
			vertex =	we->vertices;
			while (vertex) {
				vertex->newpoint = GL_FALSE;
				vertex = vertex->next;
			}
			firstDivision(we->faces);
			unitize(we);
			facetNormals(we);
			printf("----- First Pass -----\n");
			printf("%d Vertices.\n", vertexCount(we));
			printf("%d Faces.\n\n", faceCount(we));			
			break;
		case 'Q':
		case 'q':
			exit(1);
			break;	
		case 'R':
		case 'r':
			break;
	}
    
	if (name) {
		if (we) free(we);
		we = readOBJ(name); 
		if (!we) exit(0);
		unitize(we);
		facetNormals(we);
	}
    
	redisplay_all();
}


Topic archived. No new replies allowed.