Advertisement

Frustrating Errors on compile

Started by March 10, 2003 10:26 PM
21 comments, last by adam17 21 years, 11 months ago
Here is the problem file. Sorry the code is not very clean

        //#include "import.h"/*void Add_Mesh(MESH *new_mesh){	if(mesh_head)		//if head!=NULL => there are items in the list	{		mesh_tail->o_pnext = new_mesh;		mesh_tail = new_mesh;	}	else				//if there are no values => point head	{					//and tail to new mesh		mesh_head = mesh_tail = new_mesh;	}}void Add_Material(MATERIAL *new_mat){	if(mat_head)	{		mat_tail->m_pnext = new_mat;		mat_tail = new_mat;	}	else	{		mat_head = mat_tail = new_mat;	}}*//*This is line 31*/MESH MeshResize(MESH array, int new_len){	MESH	*new_array = NULL;	new_array = new MESH[new_len];	for(int x=0; x<new_len-1; x++)		new_array[x] = array;	delete[] array;	return new_array;}MATERIAL MatResize(MATERIAL array, int new_len){	MATERIAL	*new_array = NULL;	new_array = new MATERIAL[new_len];	for(int x=0; x<new_len-1; x++)		new_array[x] = array;	//delete[] array;	return new_array;}void Import(apstring fname){	apstring	dummy;        //materials defined here	//MATERIAL	Material = (MESH*)0;		//MATERIAL	*mat_head = NULL;  //points to head of list	//MATERIAL	*mat_tail = NULL;  //points to tail of list	infile.open(fname);	while(!infile.eof())	{			infile>>dummy;				if(dummy == "*MESH")		{			//Add_Mesh(Mesh);			//Mesh->o_pnext = MESH;			Mesh_len++;			//Mesh = MeshResize(Mesh, Mesh_len);			Import_Obj();		}		Draw_Triangles();	}	infile.close();}void Import_Obj(){	apstring	dummy;	Vector3		temp_vertex;	for(int x=0; dummy != ("*GEOMOBJECT" || "*LIGHTOBJECT"); x++)	//Imports everything under the *GEOMOBJECT heading	{				infile >> dummy;		if(dummy == "*MESH_NUMVERTEX")					//Inputs number of vertices in the mesh		{			infile >> dummy;			Mesh[x].num_vertex = atoi(dummy.c_str());			Mesh[x].vertex = new Mesh[x].num_vertex;		}		if(dummy == "*MESH_NUMFACES")					//Inputs number of faces on the mesh		{			infile >> dummy;			Mesh[x].num_faces = atoi(dummy.c_str());			Mesh[x].face = new Mesh[x].num_faces;			Mesh[x].fnormal = new Vector3[Mesh[x].num_faces];			Mesh[x].vnormal = new Vector3[(Mesh[x].num_faces)*3];		}		if(dummy == "*MESH_VERTEX_LIST")				//Inputs all vertices into a 		{			infile >> dummy;			for( int x=0; x < Mesh[x].num_vertex; x++)			{				infile >> dummy >> dummy;								infile >> dummy;				Mesh[x].vertex.x = atof(dummy.c_str());				infile >> dummy;				Mesh[x].vertex.z = atof(dummy.c_str());				infile >> dummy;				Mesh[x].vertex.y = atof(dummy.c_str());			}			}		if(dummy == "*MESH_FACE_LIST")		{			infile >> dummy;			for( int x=0; x < Mesh[x].num_faces; x++)			{				infile >> dummy >> dummy >> dummy;				infile >> dummy;				Mesh[x].face.x = atoi(dummy.c_str());				infile >> dummy >> dummy;				Mesh[x].face.y = atoi(dummy.c_str());				infile >> dummy >> dummy;				Mesh[x].face.z = atoi(dummy.c_str());				infile >> dummy;				Mesh[x].dir.x = atoi(dummy.c_str());				infile >> dummy;				Mesh[x].dir.y = atoi(dummy.c_str());				infile >> dummy;				Mesh[x].dir.z = atoi(dummy.c_str());				infile >> dummy >> dummy >> dummy >> dummy;			}		}		if(dummy == "*MESH_NORMALS")		{						for(int x=0; x<Mesh[x].numfaces; x++)			{				infile >> dummy;				if(dummy == "*MESH_FACENORMAL")				{					infile >> dummy >> dummy;					infile >> dummy;					Mesh[x].fnormal[x].x = atof(dummy.c_str());					infile >> dummy;					Mesh[x].fnormal[x].y = atof(dummy.c_str());					infile >> dummy;					Mesh[x].fnormal[x].z = atof(dummy.c_str());				}				if(dummy == "*MESH_VERTEXNORMAL")				{					for(int y=0; y<3; y++)					{						infile >> dummy;						infile >> dummy;						Mesh[x].vnormal[(2*(x-1)+x)+0].x = atof(dummy.c_str());						infile >> dummy;						Mesh[x].vnormal[(2*(x-1)+x)+1].y = atof(dummy.c_str());						infile >> dummy;						Mesh[x].vnormal[(2*(x-1)+x)+2].z = atof(dummy.c_str());						infile >> dummy;					}				}			}		}	}}apstring Resize(apstring String, int Num){	apstring temp_String="";	int temp_strlen = String.length();		for(int x = 0; x < (temp_strlen-Num); x++)		temp_String += String[x];	return temp_String;}GLuint Draw_Triangles()		//Rewrite to draw triangles{	Vector3 vector;	Vector3 vector2;	int a, b, c;	map=glGenLists(1);	glNewList(map,GL_COMPILE);	for(int x=0; x<Mesh_len; x++)	{		glColor4f( 1, 1, 1, 1);		for(int face = 0; face < Mesh[x].num_faces; face++)		{			//DRAWS THE FACE NORMAL			glNormal3f(Mesh[x].fnormal[x].x,						Mesh[x].fnormal[x].y,						Mesh[x].fnormal[x].z);			glBegin(GL_TRIANGLES);			//DRAWS VERTEX NORMALS FOR SMOOTH SHADING			a = Mesh[x].face[face].x;			b = Mesh[x].face[face].y;			c = Mesh[x].face[face].z;			glNormal3f(Mesh[x].vnormal[(2*(face-1)+face)+0].x,						Mesh[x].vnormal[(2*(face-1)+face)+0].y,						Mesh[x].vnormal[(2*(face-1)+face)+0].z);							glVertex3f(Mesh[x].vertex[a].x,						Mesh[x].vertex[a].y,						Mesh[x].vertex[a].z);			glNormal3f(Mesh[x].vnormal[(2*(face-1)+face)+1].x,						Mesh[x].vnormal[(2*(face-1)+face)+1].y,												Mesh[x].vnormal[(2*(face-1)+face)+1].z);			glVertex3f(Mesh[x].vertex[b].x,						Mesh[x].vertex[b].y,						Mesh[x].vertex[b].z);			glNormal3f(Mesh[x].vnormal[(2*(face-1)+face)+2].x,						Mesh[x].vnormal[(2*(face-1)+face)+2].y,						Mesh[x].vnormal[(2*(face-1)+face)+2].z);			glVertex3f(Mesh[x].vertex[c].x,						Mesh[x].vertex[c].y,						Mesh[x].vertex[c].z);				glEnd();		}	}	glEndList();	glColor4f(1, 1, 1, 1);	return map;}  

Here is the header file for it

        //Following code is for importing ASCII filesint					Num_Vertices;int					Num_Faces;//char				*filename;unsigned int				map;ifstream			infile;ofstream			outfile;//apmatrix<float>		Vertices( 3, 8, 0);//apmatrix<float>		Face( 6, 12, 0);//apstring			dummy_vector;apstring			fname;struct	RGB{	float r, g, b;};struct	LAYER{	apstring	Name,				Class,				Location,				Filter;	int			Subno,				Noise_level;	float		Amount,				Angle,				Blur,				Blur_offset,				Noise_amt,				Noise_size,				Noise_phase;	POINT		Offset,				Tiling;	//LAYER		l_pnext;};struct	MATERIAL{	int			Mat_ID;	apstring	Mat_name,				Mat_file;				//Shading,				//Falloff,				//XP_type;	RGB			rgb_Ambient,				rgb_Diffuse,				rgb_Specular;	float		//Shine,				//Shine_Strength,				Transparency;				//Wiresize,				//XP_Falloff,				//Selffillum;	//LAYER		Diffuse;	//MATERIAL	*m_pnext = (MATERIAL*)0;};struct	MESH{	int			num_vertex,				num_faces,				num_t_vertex,			//number of textured vertices				mat_id;	Vector3*	vertex;		//holds xyz values for vertices	Vector3*	face;		//holds 3 values for triangle vertices	Vector3*	dir;		//holds 3 values for winding polygon	Vector3*	fnormal;	//holds 3 values for face normals	Vector3*	vnormal;	//holds 3 values for vertex normals	//MATERIAL	*mat_ref = NULL;	//MESH		*o_pnext = NULL;	//points to next object in list};MESH		Mesh[1];int			Mesh_len = 1;MATERIAL	Material[1];int			Mat_len = 1;//void		Add_Mesh(MESH *new_mesh);			//NOT NEEDED//void		Add_Material(MATERIAL *new_mat);	//NOT NEEDEDvoid		Import(apstring fname);apstring	Resize(apstring String, int Num);GLuint		Draw_Triangles();MESH MeshResize(MESH array, int new_len);MATERIAL MatResize(MATERIAL array, int new_len);#include "import.cpp"  

Here are some of the definitions like "Vector3"

              #include <windows.h>		// Header File For Windows#include <stdio.h>			// Header File For Standard Input/Output#include <math.h>#include <fstream.h>#include <apstring.h>#include <apmatrix.h>#include <stdarg.h>#include <gl\gl.h>			// Header File For The OpenGL32 Library#include <gl\glu.h>			// Header File For The GLu32 Library#include <gl\glaux.h>		// Header File For The Glaux Library#include "glut.h"#define SCREEN_WIDTH 800								// We want our screen width 800 pixels#define SCREEN_HEIGHT 600								// We want our screen height 600 pixelsstruct Vector3{	Vector3() {}			// default constructor	Vector3(float X, float Y, float Z)	{	x = X; y = Y; z = Z;}	Vector3 operator-(Vector3 vector)	{ return Vector3( x - vector.x, y - vector.y, z - vector.z);}	Vector3 operator+(Vector3 vector)	{ return Vector3( x + vector.x, y + vector.y, z + vector.z);}	Vector3 operator=(Vector3 vector)	{ return Vector3( x = vector.x, y = vector.y, z = vector.z);}	/*Vector3 operator/(Vector3 vector, float num)	{ return Vector3( vector.x/3, vector.y/3, vector.z/3);}*/	float	x, y, z;	Vector3	*v_pnext;};Vector3 Cross(Vector3 vector1, Vector3 vector2){	Vector3	temp_vector;	temp_vector.x = (vector1.z * vector2.y) - (vector1.y * vector2.z);	temp_vector.y = (vector1.x * vector2.z) - (vector1.z * vector2.x);	temp_vector.z = (vector1.y * vector2.x) - (vector1.x * vector2.y);	return temp_vector;}float Magnitude(Vector3 vector){		return sqrt(vector.x * vector.x +				vector.y * vector.y +				vector.z * vector.z);}Vector3 Normalize(Vector3 vector){	float len = Magnitude(vector);	vector.x /= len;	vector.y /= len;	vector.z /= len;	return vector;}/*//vector1 is the normal, vector2 is the test vertex//if return > 0 => vector2 is in front of plane//if return = 0 => vector2 is on the plane//if return < 0 => vector2 is behind the planeVector3 Plane_Equ(Vector3 vector1, Vector3 vector2){	Vector3 temp_vector;	temp_vector.x = vector1.x * vector2.x;	temp_vector.y = vector1.y * vector2.y;	temp_vector.z = vector1.z * vector2.z;	temp_vector = Magnitude(vector2) + temp_vector;		return temp_vector;}*///Initializebool		keys[256];			// Array Used For The Keyboard Routinebool		active=TRUE;		// Window Active Flag Set To TRUE By Defaultbool		fullscreen=TRUE;	// Fullscreen Flag Set To Fullscreen Mode By Defaultbool		light;				//Lighting ON/OFFbool		blend;				//Blending OFF/ONbool		lp;					//'L' pressed?bool		fp;					//'F' pressed?bool		bp;					//'B' pressed?const float piover180 = 0.0174532925f;POINT	MousePos;				//Holds mouse position in a two variable structconst int	Z_Buffer = 32;int			middleX = SCREEN_WIDTH >> 1;int			middleY = SCREEN_HEIGHT >> 1;int			loop;GLuint		filter;//include files that require main.h definitions#include	"texture.h"#include	"player.h"#include	"import.cpp"//#include	"font.h"#include	"particles.h"  

i hope this helps out

[edited by - adam17 on March 12, 2003 11:24:09 AM]
It helped!!!
//#include "import.h"
try to get rid of the comment



PM


times change


Excuse my poor english!
PM Times change... Excuse my poor english!
Advertisement
it doesnt work. it only gives me 105 redefinition errors
First, I think you need to include the h file. The problem seems to be with the MESH type, it doesn''t know it. Include the h file where the MESH type is defined. Make sure you define the type as a typedef. Ex:
typedef struct _MESH
{
//members here

}MESH;

You did not put the typedef keyword, so maybe thats it.
here is a set of errors i have gotten a while back. if u look at the code there is a variable called map which has a data type of unsigned int. it used to be GLuint. if i comment out "ifstream infile" then the next line contains the error. any ideas of what could be wrong?


  --------------------Configuration: OpenGL Window - Win32 Release--------------------Compiling...import.cppG:\Adam\Software\Visual C++\OGL Window 2\import.h(7) : error C2146: syntax error : missing '';'' before identifier ''infile''G:\Adam\Software\Visual C++\OGL Window 2\import.h(7) : error C2501: ''ifstream'' : missing storage-class or type specifiersG:\Adam\Software\Visual C++\OGL Window 2\import.h(7) : fatal error C1004: unexpected end of file foundmain.cppG:\Adam\Software\Visual C++\OGL Window 2\import.cpp(40) : error C2440: ''delete'' : cannot convert from ''struct _MESH'' to ''''        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be calledG:\Adam\Software\Visual C++\OGL Window 2\import.cpp(40) : fatal error C1903: unable to recover from previous error(s); stopping compilationError executing cl.exe.OpenGL Window.exe - 5 error(s), 0 warning(s)  
1.I think you should write
#pragma once
at the beginning of header ( redefinition )
2. it is #define GLuint unsigned int so when you write GLuint the compiler will see it as unsigned int
3.include stdlib and stdio in the beginning of import.cpp (for file io)


PM


Times change...


Excuse my poor english!
PM Times change... Excuse my poor english!
Advertisement
a couple of things I''d like to say.

v_d_d: AFAIK that is only a requirement on pure C compilers, as in C unless the typedef is there you must declare variables as "struct MESH" rather than "MESH", but if I''m right, that would produce different errors.

PM: a better, definitely more portable way of doing the #pragma once thing is to add at to the header:


  #ifndef HEADER_H // or whatever)#define HEADER_H// ... file#endif  


so the first time it''s included, HEADER_H isn''t included, so it defines it, then next time through, HEADER_H is included, and so the file isn''t processed a second time.

to the OP, try leaving the #include "import.h" in, and make sure you have the headers for ifstreams included.

500x2
PM im new to windows programming so would you tell me what #pragma is and what it does and where i should put it.
baldurk i did the #ifndef, #define and #ifend lines but it still doesnt work.

what does #pragma do? is it something like #define or #include? and do i really need it?
quote:
Original post by PM
Original post by adam17
PM im new to windows programming so would you tell me what #pragma is and what it does and where i should put it.
baldurk i did the #ifndef, #define and #ifend lines but it still doesnt work.

what does #pragma do? is it something like #define or #include? and do i really need it?


1. #pragma is Microsoft-Specific
2. ''#pragma once'' says the compiler that he should include the file only once…
3. Just write it at the beginning of a file
4. There are other pragmas, like
#pragma warning
to disable/enable some warning msg
…..
Like i said, it is Microsoft specific (Visual C++)
If u want to do this without pragmas, write this:

      #ifndef __HEADERNAME_H__#define __HEADERNAME_H__// Here the header contents#endif      

The preprocessor will do this:
#ifndef __HEADERNAME_H__
if __HEADERNAME_H__ is defined go on with this file
if __HEADERNAME_H__ is not defined, jump after the next #endif
#define __HEADERNAME_H__
defines __HEADERNAME_H__ so the next time when including this file in the same compilation (in the same .cpp file), the preprocessor will skip the #ifdef … #endif part.


Huh, I hope this helped
When not just write Ill try to explain it in an other way…



PM


Times change…


Excuse my poor english!

PM Times change... Excuse my poor english!
since i still have this thread goin i might as well us it.

when i compile my program i get a lot of unresolved external errors. it tells me which classes it cant find. all of the classes that have errors came with the compiler. anyway all of the files in my program are included in one file main.h. all of the header files that i created are included at the very end. if i include them at the end of main.h i get the unresolved externals. if i include main.h in the files i made i get at least 100 errors telling me variables are being redefined. any ideas?

This topic is closed to new replies.

Advertisement