Steve
Steve

Reputation: 83

GLFW will not compile

/usr/bin/ld: /tmp/ccdsfpEq.o: warning: relocation against `glad_glViewport' in read-only section `.text'
/usr/bin/ld: /tmp/ccdsfpEq.o: in function `main':
main.cpp:(.text+0xc7): undefined reference to `gladLoadGLLoader'
/usr/bin/ld: /tmp/ccdsfpEq.o: in function `framebuffer_size_callback(GLFWwindow*, int, int)':
main.cpp:(.text+0x193): undefined reference to `glad_glViewport'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status

I don't understand this error when I tried to compile GFLW. I compiled by doing g++ main.cpp -o gl `pkg-config --libs --cflags glfw3 because I'm on Arch Linux. I generated the GLAD headers, put it in my folder, and then compiled it. I used the example code so I dont know what's wrong.

Note that this does not error when I do

int main()
{
   glfwInit();
   glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
   glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
   glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
   //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
   return 0;
}

this works. I include by

#include "glad/glad.h"
#include <GLFW/glfw3.h>
#include <iostream>

and the code where I ran was https://github.com/JoeyDeVries/LearnOpenGL/blob/master/src/1.getting_started/1.1.hello_window/hello_window.cpp

Upvotes: 1

Views: 1250

Answers (1)

Fateh A.
Fateh A.

Reputation: 372

This answer is mainly based on this post. You need to compile glad.c before you compile the code that you are writing. First, make sure that you have libglfw3-dev installed. Then compile glad.c with this line:

g++ -c glad.c

Then compile the code like this:

g++ test.cpp -o test glad.o -lglfw -ldl

Upvotes: 1

Related Questions