Archived

This topic is now archived and is closed to further replies.

vpro

anotha problem (Linux vs Windows)

Recommended Posts

vpro    122
const float pi = 3.141592654; struct _dot { GLfloat x,y,z; }; struct _tri { int first, second, third; }; struct _quad { int first, second, third, fourth; }; struct _obj { _dot dot[363]; _tri tri[363]; _quad quad[64]; int dots, tris, quads; }; int smooth=10; void create_cylinder(_obj *o) { int c; o->dots=0; o->tris=0; o->quads=0; o->tris=1; for(c=1;c<((360/smooth)+2);c++) { o->dot[1].x=0; o->dot[1].y=0; o->tri[c].third=1; o->tri[c].first=c+1; o->tri[c].second=c+2; o->dot[c+1].x=sin((pi*2)*(c*smooth)/360); o->dot[c+1].y=cos((pi*2)*(c*smooth)/360); } o->tri[c+1].third=1; o->tri[c+1].first=c+1; o->tri[c+1].second=c+2; o->tri[c+2].third=1; o->tri[c+2].first=c+1; o->tri[c+2].second=c+2; o->tri[c+3].third=1; o->tri[c+3].first=c+1; o->tri[c+3].second=c+2; for(c=1;c<=360;c++) { o->dot[c].z=0; }; } void draw_obj(void) { int c=1; _obj a_obj; c=1; create_cylinder(&a_obj); for(c=1;c<=360/smooth;c++) { glBegin(GL_TRIANGLES); glColor3f(0,0,float(rand()%2)/32+0.8f); // glVertex3f( a_obj.dot[c].x, a_obj.dot[c].y, a_obj.dot[c].z ); // glVertex3f( a_obj.dot[c].x+0.03, a_obj.dot[c].y, a_obj.dot[c].z ); // glVertex3f( a_obj.dot[c].x, a_obj.dot[c].y+0.03, a_obj.dot[c].z ); glVertex3f( a_obj.dot[a_obj.tri[c].first].x, a_obj.dot[a_obj.tri[c].first].y, a_obj.dot[a_obj.tri[c].first].z ); glVertex3f( a_obj.dot[a_obj.tri[c].second].x, a_obj.dot[a_obj.tri[c].second].y, a_obj.dot[a_obj.tri[c].second].z ); glVertex3f( a_obj.dot[a_obj.tri[c].third].x, a_obj.dot[a_obj.tri[c].third].y, a_obj.dot[a_obj.tri[c].third].z ); glEnd(); } } i got this well compiled on visual studio but when i try to port this onto a linux code it get this: [vpro@boss test]$ make gcc -Wall -I/usr/include/ -c -o lesson2.o lesson2.c In file included from lesson2.c:13: cylinder.h:19: parse error before "_dot" cylinder.h:19: warning: no semicolon at end of struct or union cylinder.h:20: warning: type defaults to `int'' in declaration of `tri'' cylinder.h:20: warning: data definition has no type or storage class cylinder.h:21: parse error before "quad" cylinder.h:21: warning: type defaults to `int'' in declaration of `quad'' cylinder.h:21: warning: data definition has no type or storage class cylinder.h:23: parse error before ''}'' token cylinder.h:26: parse error before ''*'' token cylinder.h: In function `create_cylinder'': cylinder.h:30: `o'' undeclared (first use in this function) cylinder.h:30: (Each undeclared identifier is reported only once cylinder.h:30: for each function it appears in.) cylinder.h:46: warning: implicit declaration of function `sin'' cylinder.h:47: warning: implicit declaration of function `cos'' cylinder.h: In function `draw_obj'': cylinder.h:66: `_obj'' undeclared (first use in this function) cylinder.h:66: parse error before "a_obj" cylinder.h:68: `a_obj'' undeclared (first use in this function) cylinder.h:73: parse error before "float" lesson2.c: In function `keyPressed'': lesson2.c:78: warning: implicit declaration of function `exit'' make: *** [lesson2.o] Error 1 [vpro@boss test]$

Share this post


Link to post
Share on other sites
Null and Void    1088
While that may be mostly valid C++, it''s not valid C. In C, you have to place "struct" in front of a structure type when you''re declaring variables. For example:

struct something {
int var;
};

// In C++:

something my_something;

/* In C: */
struct something my_something;

A common way to "fix" this is to use a typedef:

typedef struct {
int var;
} something;

// In either:

something my_something;

The "implicit declaration of function `exit''" is because you never included the header stdlib.h.

Share this post


Link to post
Share on other sites
Prosper/LOADED    100
It''s been a while since I''ve compiled under linux, but if memory deserves, you must either rename your file "lesson2.c" to "lesson2.C" or use g++ instead of gcc to explicitely compile in C++.

If you intended to compile C code, then follow Null and Void advice.

Share this post


Link to post
Share on other sites