By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,590 Members | 1,140 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,590 IT Pros & Developers. It's quick & easy.

Errors compiling game source code

P: 4
I download a game's source code from internet.
this is the link RapidShare: Easy Filehosting

I tried to compile it, the main.cpp file. but it gave errors.
In file included from main.cpp
[Warning] no newline at end of file

can somebody help me?

this is the main.cpp code

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <GL/glut.h>
  3. #include "Marble.h"
  4. #include "Board.h"
  5. #include "Move.h"
  6. #include "Main.h"
  7.  
  8. int Xmouse, Ymouse;
  9.  
  10. GLfloat Zoom = -14.f;
  11. GLfloat Xrot = 0.f;
  12. GLfloat Yrot = 0.f;
  13. GLfloat Zrot = 0.f;
  14.  
  15. Node *SelectedNode = 0;
  16.  
  17. main(int argc, char **argv)
  18. {
  19. glutInit(&argc, argv);
  20. glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
  21. glutInitWindowPosition(100, 100);
  22. glutInitWindowSize(500, 500);
  23. glutCreateWindow(argv[0]);
  24.  
  25. MakeGameBoard();
  26. ResetGameBoard();
  27.  
  28. glClearColor(0.f, 0.f, 0.f, 0.f);
  29. glEnable(GL_DEPTH_TEST);
  30. glEnable(GL_LIGHT0);
  31. glEnable(GL_LINE_SMOOTH);
  32. glEnable(GL_BLEND);
  33. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  34. glLineWidth(1.3f);
  35. glShadeModel(GL_SMOOTH);
  36.  
  37. glMatrixMode(GL_PROJECTION);
  38. glLoadIdentity();
  39.  
  40. glMatrixMode(GL_MODELVIEW);
  41. glLoadIdentity();
  42.  
  43. GLfloat MatSpec[] = {1.0f, 1.0f, 1.0f, 1.f};
  44. GLfloat MatShine[] = {50.f};
  45. GLfloat DiffuseLight[] = {0.6f, 0.6f, 0.6f, 1.f};
  46. GLfloat LightPos[] = {1.f, 1.f, 1.f, 0.f};
  47.  
  48. glMaterialfv(GL_FRONT, GL_SPECULAR, MatSpec);
  49. glMaterialfv(GL_FRONT, GL_SHININESS, MatShine);
  50.  
  51. glLightfv(GL_LIGHT0, GL_DIFFUSE, DiffuseLight);
  52. glLightfv(GL_LIGHT0, GL_POSITION, LightPos);
  53.  
  54. glutDisplayFunc(display);
  55. glutReshapeFunc(reshape);
  56. glutKeyboardFunc(keyboard);
  57. glutMouseFunc(mouse);
  58. glutMotionFunc(motion);
  59. glutIdleFunc(idle);
  60.  
  61. glutMainLoop();
  62.  
  63. return(0);
  64. }
  65.  
  66. void display(void)
  67. {
  68. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  69.  
  70. glMatrixMode(GL_MODELVIEW);
  71. glPushMatrix();
  72.  
  73. glTranslatef(0.f, 0.f, Zoom);
  74.  
  75. glRotatef(Xrot, 1.f, 0.f, 0.f);
  76. glRotatef(Yrot, 0.f, 1.f, 0.f);
  77. glRotatef(Zrot, 0.f, 0.f, 1.f);
  78.  
  79. RenderGameBoard(GL_RENDER);
  80.  
  81. glPopMatrix();
  82.  
  83. glutSwapBuffers();
  84. }
  85.  
  86. void reshape(int w, int h)
  87. {
  88. glViewport(0, 0, w, h);
  89. glMatrixMode(GL_PROJECTION);
  90. glLoadIdentity();
  91. gluPerspective(60.f, GLfloat(w) / GLfloat(h), 1.f, 1000.f);
  92. glMatrixMode(GL_MODELVIEW);
  93. }
  94.  
  95. void mouse(int button, int state, int x, int y)
  96. {
  97. switch(state)
  98. {
  99. case GLUT_UP:
  100. {
  101. break;
  102. }
  103. case GLUT_DOWN:
  104. {
  105. Xmouse = x;
  106. Ymouse = y;
  107.  
  108. switch(button)
  109. {
  110. case GLUT_LEFT_BUTTON:
  111. {
  112. CompletePendingMove();
  113.  
  114. Node *N = PickNode(x, y);
  115.  
  116. if(!N || N == SelectedNode)
  117. {
  118. SelectedNode = 0;
  119. }
  120. else if(MakeMove(SelectedNode, N))
  121. {
  122. JumpingNode = SelectedNode;
  123. SelectedNode = 0;
  124. }
  125. else
  126. {
  127. SelectedNode = N;
  128. }
  129.  
  130. break;
  131. }
  132. case GLUT_RIGHT_BUTTON:
  133. {
  134. break;
  135. }
  136. }
  137.  
  138. break;
  139. }
  140. }
  141.  
  142. glutPostRedisplay();
  143. }
  144.  
  145. void motion(int x, int y)
  146. {
  147. Xrot += GLfloat(y - Ymouse);
  148. Zrot += GLfloat(x - Xmouse);
  149.  
  150. Ymouse = y;
  151. Xmouse = x;
  152.  
  153. glutPostRedisplay();
  154. }
  155.  
  156. void keyboard(unsigned char key, int x, int y)
  157. {
  158. switch(key)
  159. {
  160. case '[':
  161. {
  162. Zoom -= 1.2f;
  163. break;
  164. }
  165. case ']':
  166. {
  167. Zoom += 1.2f;
  168. break;
  169. }
  170. }
  171.  
  172. glutPostRedisplay();
  173. }
  174.  
  175. void idle(void)
  176. {
  177. AnimateMovingMarbles();
  178.  
  179. glutPostRedisplay();
  180. }
  181.  
Dec 12 '08 #1
Share this Question
Share on Google+
9 Replies


Expert 10K+
P: 11,448
That one is simple: add a newline character (press enter) at the last line of the file your compiler is whining about. (the Standard says that every source file should have a newline at the end of every line in the file).

kind regards,

Jos
Dec 12 '08 #2

P: 4
thank you, I tried it, but there's no difference.

Dec 12 '08 #3

Banfa
Expert Mod 5K+
P: 8,916
It looks like the problem is not in you main.cpp but in all your header files.

All lines of code in all files must end in a new line, check all the files in the project.
Dec 12 '08 #4

Expert 10K+
P: 11,448
@gkhn86
Note that if you position your mouse between the two columns of the error message you can shift them from left to right so you can see which files contain the error. Also the number of error messages indicate that none of your .h files contain an end of line at the end of the file. Know how to use your tools.

kind regards,

Jos
Dec 12 '08 #5

P: 4
thanks for all your help. I tried to do all your said, but I couldn't get rid of the errors. I add new line for all the .cpp and .h files. but this time it gave some other errors. I think there's a little error but I couldn't find it. there is 4 .cpp files, maybe that's why it's a bit complicated for me.

here is the orijinal project, maybe somebody can help me.
RapidShare Webhosting + Webspace
Dec 12 '08 #6

Banfa
Expert Mod 5K+
P: 8,916
If you post the errors and the lines of source where your errors are occurring then we can help.

I personally do not feel like downloading source from an unknown website and seeing if I can make it compile. And even if I did that wouldn't necessarily solve your problems as we are using different platforms.
Dec 12 '08 #7

P: 4
you're right, sorry.
so there are main.cpp, marble.cpp, move.cpp, board.cpp.
and main.h, marle.h, move.h, board.h.

i add new lines for the .h files. then compile the main.cpp file. and it gave new errors.
these are the new errors.

[Linker error] undefined reference to `glutInit'
[Linker error] undefined reference to `glutInitDisplayMode'
[Linker error] undefined reference to `glutInitWindowPosition'
[Linker error] undefined reference to `glutInitWindowSize'
.
.
.
.
.
ld returned 1 exit status
Dec 12 '08 #8

Banfa
Expert Mod 5K+
P: 8,916
OK this looks like one of 2 errors (or may be both depending on the number of undefined reference errors there are).

An undefined reference means the code linked referred to a symbol which was not found in any of the objects or libraries linked. This is normally achieve either by forgetting to include one of your source files, forgetting to include a library or making a typo in a source file (mistyping a name) although that is a little harder to do in C++.

You did not compile main.cpp, you compiled and linked it, that is having compiled it you attempted to link it into a complete program. You should have used a compile command line that at least looked something like
gcc main.cpp marble.cpp move.cpp board.cpp
You may have had other compiler switches and in fact a different command in place of gcc.

Additionally if those symbols (functions) were not in your code but in a library (the OpenGL library for instance) then you would have needed to include that library on the command line too.

You may need to find/download a copy of the openGL library for your platform if you do not already have it.
Dec 12 '08 #9

boxfish
Expert 100+
P: 469
Here's what I have to do to use openglut on Dev-C++:
From the Project menu, select Project Options.
Click on the Parameters tab.
In the linker box, put
-lopenglut -lglu32 -lopengl32 -lwinmm -lgdi32
and in the other two boxes put
-DOPENGLUT_STATIC

You're using glut and I have openglut, but it seems like basically the same thing. This is just a guess, but try the above with glut instead of openglut to see if it works:
-lglut -lglu32 -lopengl32 -lwinmm -lgdi32
and
-DGLUT_STATIC

Good luck with this.
Dec 12 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.