glViewport undefined reference [duplicate]
Asked Answered
P

1

8

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.

Phylis answered 20/7, 2014 at 6:1 Comment(8)
Can you get the verbose output from the 'make' command? If compiling via command line, adding VERBOSE=1 to the command will do itKries
Unfortunately I am currently using NetBeans generated makefile. But now I am trying to find a way to use VERBOSE=1 in NetBeans makefile.Phylis
Wait, what compiler are you using? I've been assuming GCC on linux but I just noticed you're using .dll'sKries
I am using MinGW as compiler.Phylis
Ah good. Well adding a -Wl,--verbose to the command options should give more information then. That passes --verbose to the linkerKries
It gave me a really huge outputPhylis
Hmm, nothing obvious to me. Have you downloaded the guy's sample source and tried compiling that? It doesn't have the glViewport call, strangely enoughKries
I havent noticed that. Even without glViewport() there are errors. - -D:\OpenGL\OpenGLTutorial/sample.cpp:21: undefined reference to glClearColor@16' -D:\OpenGL\OpenGLTutorial/sample.cpp:22: undefined reference to glClear@4'Phylis
A
9

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).

Agrestic answered 20/7, 2014 at 9:6 Comment(3)
If adding this does not fix the issue, keep it (you need it either way) and also build glad.c. It has these stuff defined.Repairman
@am.rez: glad.c is just one of many different OpenGL loader libraries. I'd strongly recommend against mindlessly pulling in and adding 3rd party sources, without actually understanding, what's happening under the hood.Agrestic
totally agree. I was using glad.c and forgot to add its object in the link process. So I came to help future viewers, but did not notice the question did not mention glad.Repairman

© 2022 - 2024 — McMap. All rights reserved.