Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glViewport undefined reference [duplicate]

Summary

Compiler MinGW OS Windows 7 x64

glViewport() function gives Undefined Reference error

I have tried

  1. adding -lGL resulted cannot find -lGL <-- How do I locate OpenGL dll files ?
  2. checked -Lpath -lglew32 -lglfw3 as if not last linker argument

I may have miscompiled GLEW and/or miscopied GLEW libs as I am not sure if I need libglew32.a and/or libglew32.dll.a files.

I have a folder structure like that

  • OpenGL
    • bins
      • glew32.dll
      • glfw3.dll
    • includes
      • GL
        • glew.h
        • glewx.h
        • wglew.h
      • GLFW
        • glfw3.h
        • glfw3native.h
    • libs
      • glfw3.lib

Long Story

Hello experienced programmers. Your humble questioner returns. Today me and my friend decided to start/learn OpenGL. As we follow this tutorial, we have stuck at glViewport as it gives Undefined reference error. We are working on NetBeans 8.0 C/C++ version. I have double checked the Makefile as some sites mentioned -Lpath -lglew32 -lglfw3 had to be last parameter when compiling. I have tried to ad -lGL as linker option, but sadly it won't work.


Code

#include <cstdlib>
//GLEW
#include "GL/glew.h"
//GLFW
#include "GLFW/glfw3.h"

using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {
    glewExperimental = GL_TRUE;
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL , NULL);
    glfwMakeContextCurrent(window);
    glViewport(0, 0, 800, 600);

    return 0;
}

As a side note this is my first time using libraries other than standards. Well Summary looking much longer than Long Story..

Edit: I do not think this is a duplicate question as I'm asking linking of a specific library, not how can I link something in C++. This is like saying all coding questions are same as all of them involves writing code. Checked the said topic and cannot find any direction about linking opengl32 library.

like image 319
Yakup Türkan Avatar asked Jul 20 '14 06:07

Yakup Türkan


1 Answers

In Windows the OpenGL API interface library is called opengl32 not GL, hence you must link with

-lopengl32

(note that it's always …32, even on 64 bit systems).

like image 57
datenwolf Avatar answered Oct 12 '22 18:10

datenwolf