"DT_TEXTREL in a PIE" when linking?

203 views Asked by At

When trying to set up my environment, I got GLFW set up, and was able to compile the example blank window provided in the page (LINK), and also the rotating triangle one (LINK) which also requires getting GLAD, which I successfully did. Or did I?

The thing is, the sample programs compile when I do it from my home directory, but not from anywhere else.

When compiling the examples, I have an example.c file, and next to it only the linmath.h file in the case of the rotating triangle example. Inside /usr/include/glad there's the gl.h file which is a copy of the glad.h include file generated from the GLAD website. All that done, without modifying the source given in the GLFW website, I can compile as

g++ glfw_rotating_triangle.c -lglfw -lGL

Now, when I move those files somewhere else*, like /Documents/opengl_projects and try to compile with the exact same command, I get the following error:

glfw_rotating_triangle.c: In function ‘int main()’:
glfw_rotating_triangle.c:76:15: error: too many arguments to function ‘int gladLoadGL()’
   76 |     gladLoadGL(glfwGetProcAddress);
      |     ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
In file included from glfw_rotating_triangle.c:1:
/usr/include/glad/gl.h:95:11: note: declared here
   95 | GLAPI int gladLoadGL(void);

So I thought OK, maybe something changed since they uploaded the example, I'll modify the example to comply (although I shouldn't since this already compiled!!). The thing is, taking out either the argument to the function in the sample code, or just commenting the line, gets me the following error:

/usr/bin/ld: /tmp/cctdTvsz.o: warning: relocation against `glad_glViewport' in read-only section `.text'
/usr/bin/ld: /tmp/cctdTvsz.o: in function `main':
glfw_rotating_triangle.c:(.text+0x65d): undefined reference to `glad_glGenBuffers'
/usr/bin/ld: glfw_rotating_triangle.c:(.text+0x675): undefined reference to `glad_glBindBuffer'
/usr/bin/ld: glfw_rotating_triangle.c:(.text+0x68b): undefined reference to `glad_glBufferData'
[[OMITTED LINES]]
/usr/bin/ld: glfw_rotating_triangle.c:(.text+0x9aa): undefined reference to `glad_glUniformMatrix4fv'
/usr/bin/ld: glfw_rotating_triangle.c:(.text+0x9cd): undefined reference to `glad_glDrawArrays'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status

There are many more lines of undefined references in the middle, if you want to see them all they're HERE

Now, I've been reading the posts about DT_TEXTREL errors, and I can kind of understand that it has something to do with the linkage and load parts of the compilation process, and static executables? but it's getting too heavy for me and it seems like even if I understood the answers in those posts, I don't know what I'd have to do to fix my problem, let alone know WHY it started happening in the first place.

I am running Linux Mint 21.2 "Victoria", kernel is 5.15.0-91-generic. OpenGL version 4.6 and GLFW 3.3.9.

*: (I actually don't know how I ended up moving the files there, but luckily I did, since I found out there was one place where it all worked)

0

There are 0 answers