NO

Author Topic: SOLVED: Compilation problem - Unresolved external symbol  (Read 5324 times)

lowrez

  • Guest
SOLVED: Compilation problem - Unresolved external symbol
« on: April 09, 2015, 12:12:51 AM »
I've been trying to compile this code for the better part of the day. I've tried modifying the code, searching the error, etc... I've even tried other dev environments (Dev C++ and Code::Blocks). I'm stumped. Any help would be most appreciated.

Here is the code I'm trying to compile
Code: [Select]
#include <windows.h>
#include <SDL.h>
#include <GL/gl.h>

int main(int argc, char **argv)
{
/* Initialize SDL as usual. */
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Error: %s\n", SDL_GetError());
return 1;
}
atexit(SDL_Quit);

/* Enable OpenGL double buffering. */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

/* Set the color depth (16-bit 565). */
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);

/* Create a 640x480, 16 bit window with support for
OpenGL rendering. Unfortunately we won’t know
whether this is hardware accelerated. */
if (SDL_SetVideoMode(640, 480, 16, SDL_OPENGL) == NULL) {
printf("Error: %s\n", SDL_GetError());
return 1;
}

/* Set a window title. */
SDL_WM_SetCaption("OpenGL with SDL!", "OpenGL");

/* We can now use any OpenGL rendering commands. */
glViewport(80, 0, 480, 480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0);
glClearColor(0, 0, 0, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_TRIANGLES);
glColor3f(1.0, 0, 0);
glVertex3f(0.0, 1.0, -2.0);
glColor3f(0, 1.0, 0);
glVertex3f(1.0, -1.0, -2.0);
glColor3f(0, 0, 1.0);
glVertex3f(-1.0, -1.0, -2.0);
glEnd();

glFlush();

/* Display the back buffer to the screen. */
SDL_GL_SwapBuffers();
/* Wait a few seconds. */
SDL_Delay(5000);
return 0;
}

This gives the following error:
Code: [Select]
Building main.obj.
Use <stdlib.h> instead of non-standard <malloc.h>
Building SDL_OPENGL.exe.
POLINK: error: Unresolved external symbol '__imp_glViewport'.
POLINK: error: Unresolved external symbol '__imp_glMatrixMode'.
POLINK: error: Unresolved external symbol '__imp_glLoadIdentity'.
POLINK: error: Unresolved external symbol '__imp_glFrustum'.
POLINK: error: Unresolved external symbol '__imp_glClearColor'.
POLINK: error: Unresolved external symbol '__imp_glClear'.
POLINK: error: Unresolved external symbol '__imp_glBegin'.
POLINK: error: Unresolved external symbol '__imp_glColor3f'.
POLINK: error: Unresolved external symbol '__imp_glVertex3f'.
POLINK: error: Unresolved external symbol '__imp_glEnd'.
POLINK: error: Unresolved external symbol '__imp_glFlush'.
POLINK: fatal error: 11 unresolved external(s).
*** Error code: 1 ***
Done.

If I make 1 change and remove all of the the gl drawing code it compiles and runs fine. Example:
Code: [Select]
#include <windows.h>
#include <SDL.h>
#include <GL/gl.h>

int main(int argc, char **argv)
{
/* Initialize SDL as usual. */
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Error: %s\n", SDL_GetError());
return 1;
}
atexit(SDL_Quit);

/* Enable OpenGL double buffering. */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

/* Set the color depth (16-bit 565). */
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);

/* Create a 640x480, 16 bit window with support for
OpenGL rendering. Unfortunately we won’t know
whether this is hardware accelerated. */
if (SDL_SetVideoMode(640, 480, 16, SDL_OPENGL) == NULL) {
printf("Error: %s\n", SDL_GetError());
return 1;
}

/* Set a window title. */
SDL_WM_SetCaption("OpenGL with SDL!", "OpenGL");

/* Display the back buffer to the screen. */
SDL_GL_SwapBuffers();
/* Wait a few seconds. */
SDL_Delay(5000);
return 0;
}

But then I can't draw anything so there is no point. :/

Any ideas?
« Last Edit: April 09, 2015, 06:06:15 PM by lowrez »

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: ► Compilation problem - Unresolved external symbol
« Reply #1 on: April 09, 2015, 12:54:41 AM »
If I make 1 change and remove all of the the gl drawing code it compiles and runs fine.

But then I can't draw anything so there is no point. :/

Any ideas?
Yes, you are missing the library/.c file that contains the actual code for those drawing functions. The "gl.h" file is only the header, which describes the interface of the functions but does not (should not!) contain any actual code...

Ralf

lowrez

  • Guest
Re: ► Compilation problem - Unresolved external symbol
« Reply #2 on: April 09, 2015, 01:13:46 AM »
Hmm gl.h came with Pelles C. I don't see a .lib or .c file that seems to correlate with gl.h.
« Last Edit: April 09, 2015, 02:49:46 AM by lowrez »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: ► Compilation problem - Unresolved external symbol
« Reply #3 on: April 09, 2015, 05:06:30 AM »
Hmm gl.h came with Pelles C. I don't see a .lib or .c file that seems to correlate with gl.h.
opengl32.lib
May the source be with you

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: ► Compilation problem - Unresolved external symbol
« Reply #4 on: April 09, 2015, 05:08:50 AM »
Hmm gl.h came with Pelles C. I don't see a .lib or .c file that seems to correlate with gl.h.
Please ZIP the whole project (right click on the project in the right hand window) and post it here. I don't see on a quick cursory look neither a file gl.h nor a folder called GL in my standard Pelle's C installation. (Windows 8.1/64, 64bit compiler).

The basic error, with the little info you have given so far, simply tells you that you are calling functions that are not in either one of the compiled .c files of your project nor in one of the .obj/.lib file in the linker path...

Ralf

lowrez

  • Guest
Re: ► Compilation problem - Unresolved external symbol
« Reply #5 on: April 09, 2015, 05:48:14 PM »
Linking opengl32.lib did the trick. Thanks :D
« Last Edit: April 09, 2015, 06:07:11 PM by lowrez »