943,701 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 3203
  • C RSS
Mar 1st, 2008
1

OpenGL in C (errors)

Expand Post »
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.
Similar Threads
Reputation Points: 34
Solved Threads: 4
Light Poster
midimatt is offline Offline
49 posts
since Mar 2008
Mar 1st, 2008
0

Re: OpenGL in C (errors)

Maybe this will help
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Mar 1st, 2008
0

Re: OpenGL in C (errors)

Click to Expand / Collapse  Quote originally posted by Aia ...
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.
Reputation Points: 34
Solved Threads: 4
Light Poster
midimatt is offline Offline
49 posts
since Mar 2008
Mar 1st, 2008
0

Re: OpenGL in C (errors)

Install the glut devpak
http://www.nigels.com/glt/devpak/
Reputation Points: 78
Solved Threads: 22
Posting Whiz
Colin Mac is offline Offline
327 posts
since Sep 2006
Mar 1st, 2008
0

Re: OpenGL in C (errors)

ALready installed the Devpak, was the first thing i did.
Reputation Points: 34
Solved Threads: 4
Light Poster
midimatt is offline Offline
49 posts
since Mar 2008
Mar 1st, 2008
0

Re: OpenGL in C (errors)

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.
Reputation Points: 78
Solved Threads: 22
Posting Whiz
Colin Mac is offline Offline
327 posts
since Sep 2006
Mar 1st, 2008
0

Re: OpenGL in C (errors)

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.
Reputation Points: 34
Solved Threads: 4
Light Poster
midimatt is offline Offline
49 posts
since Mar 2008
Mar 1st, 2008
0

Re: OpenGL in C (errors)

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.
Reputation Points: 78
Solved Threads: 22
Posting Whiz
Colin Mac is offline Offline
327 posts
since Sep 2006
Mar 1st, 2008
0

Re: OpenGL in C (errors)

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.
Reputation Points: 34
Solved Threads: 4
Light Poster
midimatt is offline Offline
49 posts
since Mar 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: problem with loop
Next Thread in C Forum Timeline: Median.c Please Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC