OpenGL in C (errors)

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2008
Posts: 40
Reputation: midimatt is an unknown quantity at this point 
Solved Threads: 2
midimatt's Avatar
midimatt midimatt is offline Offline
Light Poster

OpenGL in C (errors)

 
1
  #1
Mar 1st, 2008
I'm getting Linker errors when trying to compile my OpenGL code with Dev C++, the code compiles perfectly on the university machines using Visual Studio.

I've visited several sites that explain how to get openGL to work om Dev C++, and i've followed the steps.

-Installed the Dev Pack.
-added the glut32.dll file
-changed the parameters in the project options

the parameters are "-lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32" i've tried entering all on same line, i've tried 1 line per parameter but still i get linker errors.

i've hit a brick wall and no idea where to go from here.

Here is the code that i have so far(its for drawing a simple robotic arm);

  1. #include <windows.h>
  2. #include <gl/gl.h>
  3. #include <gl/glu.h>
  4. #include <gl/glut.h>
  5.  
  6.  
  7. static int shoulder = 0, elbow = 0, wrist = 0, finger1 = 0,finger2 = 0, finger3 = 0;
  8.  
  9. void init(void)
  10. {
  11. glClearColor (0.0, 0.0, 0.0, 0.0);
  12. glShadeModel (GL_FLAT);
  13. }
  14.  
  15.  
  16. void display(void)
  17. {
  18. glClear (GL_COLOR_BUFFER_BIT);
  19. glPushMatrix();
  20. glTranslatef (-1.0, 0.0, 0.0);
  21. glRotatef ((GLfloat) shoulder, 0, 90, 1.0);
  22. glTranslatef (1.0, 0.0, 0.0);
  23. glPushMatrix();
  24. glScalef (2.0, 0.4, 1.0);
  25. glColor3f(1,1,1);
  26. glutSolidCube (1.0);
  27. glPopMatrix();
  28.  
  29. glTranslatef (1.0, 0.0, 0.0);
  30. glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0);
  31. glTranslatef (1.0, 0.0, 0.0);
  32. glPushMatrix();
  33. glScalef (2.0, 0.4, 1.0);
  34. glColor3f(0.9,0.9,0.9);
  35. glutSolidCube (1.0);
  36. glPopMatrix();
  37.  
  38. glTranslatef (1.0, 0.0, 0.0);
  39. glRotatef ((GLfloat) wrist, 0.0, 0.0, 1.0);
  40. glTranslatef (1.0, 0.0, 0.0);
  41. glPushMatrix();
  42. glScalef (2.0, 0.4, 1.0);
  43. glColor3f(0.8,0.8,0.8);
  44. glutSolidCube (1);
  45. glPopMatrix();
  46.  
  47. glPushMatrix();
  48. glTranslatef (0.5, 0.0, 0.75);
  49. glRotatef ((GLfloat) finger1, 0.0, 0.0, 1.0);
  50. glTranslatef (1.0, 0.0, 0.0);
  51. glPushMatrix();
  52. glScalef (2.0, 0.4, 1.0);
  53. glColor3f(0.8,0.8,0.8);
  54. glutWireCube (0.75);
  55. glPopMatrix();
  56. glPopMatrix();
  57.  
  58. glPushMatrix();
  59. glTranslatef (0.5, 0.0, 0.0);
  60. glRotatef ((GLfloat)finger2, 0.0, 0.0, 1.0);
  61. glTranslatef (1.0, 0.0, 0.0);
  62. glPushMatrix();
  63. glScalef (2.0, 0.4, 1.0);
  64. glColor3f(0.8,0.8,0.8);
  65. glutWireCube (0.75);
  66. glPopMatrix();
  67. glPopMatrix();
  68.  
  69. glPushMatrix();
  70. glTranslatef (0.5, 0.0, -0.75);
  71. glRotatef ((GLfloat) finger3, 0.0, 0.0, 1.0);
  72. glTranslatef (1.0, 0.0, 0.0);
  73. glPushMatrix();
  74. glScalef (2.0, 0.4, 1.0);
  75. glColor3f(0.8,0.8,0.8);
  76. glutWireCube (0.75);
  77. glPopMatrix();
  78. glPopMatrix();
  79.  
  80. glPopMatrix();
  81. glutSwapBuffers();
  82. }
  83.  
  84.  
  85. void reshape (int w, int h)
  86. {
  87. glViewport (0, 0, (GLsizei) w, (GLsizei) h);
  88. glMatrixMode (GL_PROJECTION);
  89. glLoadIdentity ();
  90. gluPerspective(65.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
  91. glMatrixMode(GL_MODELVIEW);
  92. glLoadIdentity();
  93. glTranslatef (0.0, 0.0, -5.0);
  94. }
  95.  
  96.  
  97. void keyboard (unsigned char key, int x, int y)
  98. {
  99. switch (key) {
  100. case 's': /* s key rotates at shoulder */
  101. shoulder = (shoulder + 5) % 360;
  102. glutPostRedisplay();
  103. break;
  104. case 'S':
  105. shoulder = (shoulder - 5) % 360;
  106. glutPostRedisplay();
  107. break;
  108. case 'e': /* e key rotates at elbow */
  109. elbow = (elbow + 5) % 360;
  110. glutPostRedisplay();
  111. break;
  112. case 'E':
  113. elbow = (elbow - 5) % 360;
  114. glutPostRedisplay();
  115. break;
  116. case 'w': /* w key rotates at wrist */
  117. wrist = (wrist + 5) % 360;
  118. glutPostRedisplay();
  119. break;
  120. case 'W':
  121. wrist = (wrist - 5) % 360;
  122. glutPostRedisplay();
  123. break;
  124. case '1':
  125. finger1 = (finger1 - 5) % 360;
  126. glutPostRedisplay();
  127. break;
  128. case '2':
  129. finger2 = (finger2 - 5) % 360;
  130. glutPostRedisplay();
  131. break;
  132.  
  133. case '3':
  134. finger3 = (finger3 - 5) % 360;
  135. glutPostRedisplay();
  136. break;
  137. default:
  138. break;
  139. }
  140. }
  141.  
  142. int main(int argc, char** argv)
  143. {
  144. glutInit(&argc, argv);
  145. glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
  146. glutInitWindowSize (500, 500);
  147. glutInitWindowPosition (100, 100);
  148. glutCreateWindow (argv[0]);
  149. init ();
  150. glutDisplayFunc(display);
  151. glutReshapeFunc(reshape);
  152. glutKeyboardFunc(keyboard);
  153. glutMainLoop();
  154. return 0;
  155. }

Examples of Errors:

[Linker Error] undefined reference to 'glutinit'
[Linker Error] undefined reference to 'glutmainloop'
[Linker Error] undefined reference to 'glutsolidcube'
[Linker Error] undefined reference to 'glutswapbuffers
[Linker Error] undefined reference to 'glutcreatewindow'
Last edited by midimatt; Mar 1st, 2008 at 11:03 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,048
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 179
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: OpenGL in C (errors)

 
0
  #2
Mar 1st, 2008
Maybe this will help
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 40
Reputation: midimatt is an unknown quantity at this point 
Solved Threads: 2
midimatt's Avatar
midimatt midimatt is offline Offline
Light Poster

Re: OpenGL in C (errors)

 
0
  #3
Mar 1st, 2008
Originally Posted by Aia View Post
Maybe this will help
Thanks for the reply, i've looked over the site and although it hasnt solved my problem it has made me think that my problem might be a missing library file so i'm gonna investigate that and see if i can get this program to run for me.

Thanks again


EDIT: Found the glut32 lib file i was missing and added that but still getting the same errors as before.
Last edited by midimatt; Mar 1st, 2008 at 11:38 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 327
Reputation: Colin Mac is on a distinguished road 
Solved Threads: 22
Colin Mac Colin Mac is offline Offline
Posting Whiz

Re: OpenGL in C (errors)

 
0
  #4
Mar 1st, 2008
Install the glut devpak
http://www.nigels.com/glt/devpak/
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 40
Reputation: midimatt is an unknown quantity at this point 
Solved Threads: 2
midimatt's Avatar
midimatt midimatt is offline Offline
Light Poster

Re: OpenGL in C (errors)

 
0
  #5
Mar 1st, 2008
ALready installed the Devpak, was the first thing i did.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 327
Reputation: Colin Mac is on a distinguished road 
Solved Threads: 22
Colin Mac Colin Mac is offline Offline
Posting Whiz

Re: OpenGL in C (errors)

 
0
  #6
Mar 1st, 2008
When you create a project did you choose Multimedia > GLUT

This is how to set it up
http://www.zeuscmd.com/tutorials/ope...php#devc++glut
Last edited by Colin Mac; Mar 1st, 2008 at 11:52 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 40
Reputation: midimatt is an unknown quantity at this point 
Solved Threads: 2
midimatt's Avatar
midimatt midimatt is offline Offline
Light Poster

Re: OpenGL in C (errors)

 
0
  #7
Mar 1st, 2008
No, i created a blank project because i'm using code that has already been created.

Creating it as an openGL project would have only put the parameters in for me and created a .C file with the correct #includes.

I already have the openGL parameters and the #includes in this project.

EDIT:

After looking at the link you gave me, i'm guessing the only thing i'm missing is a custom makefile but heres the problem

A) i've never made a make file before
B) that website doesnt go into much detail on makefiles
Last edited by midimatt; Mar 1st, 2008 at 12:01 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 327
Reputation: Colin Mac is on a distinguished road 
Solved Threads: 22
Colin Mac Colin Mac is offline Offline
Posting Whiz

Re: OpenGL in C (errors)

 
0
  #8
Mar 1st, 2008
I'm not sure what you mean exactly by using code that has already been created but your code compiled for me after I chose glut.
Last edited by Colin Mac; Mar 1st, 2008 at 12:05 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 40
Reputation: midimatt is an unknown quantity at this point 
Solved Threads: 2
midimatt's Avatar
midimatt midimatt is offline Offline
Light Poster

Re: OpenGL in C (errors)

 
0
  #9
Mar 1st, 2008
I wrote in my original post, that i've already writen and compiled the code on a machine at the university using visual studio, i've taken the code home tried to use it on on Dev C++ have been unable to compile,

I've installed the Dev Pak, i've created a blank project and put the code into the blank project.

I've changed the project parameter to include the openGL parameters. which is exactly what happens when you create a glut or openGL project from the multimedia tab.

EDIT: THought to my self maybe i should try and create a glut project, so i have, i've pasted the code in and i'm still getting linker errors

I've been to 4 sites all telling me to do the exact same things, still cant compile after doing those things

EDIT2: i've tried compiling the template code that comes with the glut project, and that also comes up with linker errors.
Last edited by midimatt; Mar 1st, 2008 at 12:18 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum


Views: 1928 | Replies: 8
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC