2012-06-30 33 views
5

मैं जब निष्पादन योग्य बनाने की कोशिश कर इस त्रुटि मिलती है, कोड सही तरीके से और अभी तक संकलित जब मैं मेकअप आदेश मारा मैं इस त्रुटि संदेश मिलता है:अपरिभाषित संदर्भ - ओपन

gcc -c helloworld.c 
[email protected] ~/Desktop/Dev/gl $ make 
gcc -o hello-gl helloworld.o -L/usr/X11R6/lib -lGL -lglut -lGLEW -lm 
helloworld.o: In function `Initialize': 
helloworld.c:(.text+0x55): undefined reference to `GlewInit' 
collect2: ld returned 1 exit status 
make: *** [helloworld] Error 1 

मैं लिनक्स टकसाल 13 चल रहा है और मुझे लगता है कि यह मेरी makefile के साथ कुछ है, मैं नहीं जानता कि उनके बारे में बहुत ज्यादा तो मैं एक साथ काट दिया और कुछ कोड ऑनलाइन पाया:

GL_INCLUDE = /usr/X11R6/include 
GL_LIB = /usr/X11R6/lib 
GL_GLEW = /user/include 

helloworld: helloworld.o 
    gcc -o hello-gl $^ -L$(GL_LIB) -lGL -lglut -lGLEW -lm 

.c.o: 
    gcc -c -o [email protected] $< -I$(GL_INCLUDE) 

clean: 
    rm -f hello-gl hello-gl-dummy hello-gl.o util.o hello-gl-dummy.o 

मेरे कोड:

#include <stdlib.h> 
#include <stdio.h> 
#include <string.h> 
#include <GL/glew.h> 
#include <GL/freeglut.h> 
#define WINDOW_TITLE_PREFIX "Hello, World!" 

int CurrentWidth = 600, 
    CurrentHeight = 400, 
    WindowHandle = 0; 

void Initialize(int, char*[]); 
void InitWindow(int, char*[]); 
void ResizeFunction(int, int); 
void RenderFunction(void); 

int main(int argc, char* argv[]) 
{ 
    Initialize(argc, argv); 

    glutMainLoop(); 

    exit(EXIT_SUCCESS); 
     return 0; 
} 

void Initialize(int argc, char* argv[]) 
{ 
    GLenum GlewInitResult; 
    InitWindow(argc, argv); 
     GlewInitResult = GlewInit(); 
     if (GLEW_OK != GlewInitResult) { 
      fprintf(stderr, "ERROR: %s\n", glewGetErrorString(GlewInitResult)); 
      exit(EXIT_FAILURE); 
     } 

    fprintf(
     stdout, 
     "INFO: OpenGL Version: %s\n", 
     glGetString(GL_VERSION) 
    ); 

    glClearColor(0.2f, 1.0f, 0.8f, 0.3f); 
} 

void InitWindow(int argc, char* argv[]) 
{ 
    glutInit(&argc, argv); 

    glutInitContextVersion(4, 0); 
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE); 
    glutInitContextProfile(GLUT_CORE_PROFILE); 

    glutSetOption(
     GLUT_ACTION_ON_WINDOW_CLOSE, 
     GLUT_ACTION_GLUTMAINLOOP_RETURNS 
    ); 

    glutInitWindowSize(CurrentWidth, CurrentHeight); 

    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); 

     char *states[] = {"Hello", "My", "Name", "Is", "Lewis"}; 

    WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX); 

    if(WindowHandle < 1) { 
     fprintf(
      stderr, 
      "KERN_ERROR: Could not create a new rendering window.\n" 
     ); 
     exit(EXIT_FAILURE); 
    } 

    glutReshapeFunc(ResizeFunction); 
    glutDisplayFunc(RenderFunction); 
} 

void ResizeFunction(int Width, int Height) 

    { 
     /*captures the resize data from the OS and assigns it to the global 
     variable CURRENT_WIDTH & CURRENT_HEIGHT */ 

    CurrentWidth = Width; 
    CurrentHeight = Height; 
    glViewport(0, 0, CurrentWidth, CurrentHeight); 
} 

void RenderFunction(void) 
{ 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    /*the next line takes the data from the back-buffer to the screen */ 

    glutSwapBuffers(); 
    glutPostRedisplay(); 
} 
+2

इस लाइन के लिए +1: gcc -o hello-gl helloworld.o -L/usr/X11R6/lib -lGL -lglut -lGLEW -lm यह मेरी मदद करता है :) – rendon

+0

@DDC मुझे खुशी है कि मेकफ़ाइल ने आपकी मदद की :) – TheBlueCat

उत्तर

4

GLEW फ़ंक्शंस के लिए नाम 'glew' से शुरू होना चाहिए, न कि 'Glew'।

तो यह है

GlewInitResult = glewInit(); 

सी केस-संवेदी है और सभी ओपन से संबंधित libs आमतौर पर छोटे अक्षरों के साथ कार्यों के नाम शुरू करते हैं।

+0

धन्यवाद! मैंने एक टाइपो बनाया होगा। – TheBlueCat