0

I am trying to build two c++ files. These include the GLFW and GLEW libraries, as I'm trying to write OpenGL code. App.cpp is the main file, and loadShader.cpp is the implementation file of loadShader.h.
The Libraries and Include folders are in another folder called "Imports"

I am using Mingw32 as my compiler and vscode as my code editor.

In the integrated terminal I tried running the following command:
Working directory> g++ -O2 -Wall -o OpenGL "src/App.cpp" "src/header files/loadShader.cpp" -I "Imports/GLEW/include" -I "Imports/GLFW/include" -I "Imports/glm" -L "Imports/GLEW/lib/Release/Win32" -L "Imports/GLFW/lib-vc2022"
When I run the command, it doesn't give me any errors about not finding the libraries or include files/folders specified. It only gives me the error after it starts trying to compile App.cpp and loadShader.cpp

C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x1e): undefined reference to _imp__glewExperimental' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x26): undefined reference to glfwInit' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x42): undefined reference to glfwWindowHint' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x56): undefined reference to glfwWindowHint' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x6a): undefined reference to glfwWindowHint' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x7e): undefined reference to glfwWindowHint' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x92): undefined reference to glfwWindowHint' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0xbe): undefined reference to glfwCreateWindow' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0xd0): undefined reference to glfwMakeContextCurrent' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0xd9): undefined reference to _imp__glewInit@0' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0xff): undefined reference to _imp____glewGenVertexArrays' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x112): undefined reference to _imp____glewBindVertexArray' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x12f): undefined reference to glfwSetInputMode' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x2d6): undefined reference to _imp____glewGetUniformLocation' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x2f7): undefined reference to _imp____glewGenBuffers' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x305): undefined reference to _imp____glewBindBuffer' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x31b): undefined reference to _imp____glewBufferData' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x355): undefined reference to _imp____glewGenBuffers' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x3af): undefined reference to glClearColor@16' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x3b5): undefined reference to _imp____glewEnableVertexAttribArray' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x3c4): undefined reference to glClear@4' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x3d5): undefined reference to _imp____glewUseProgram' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x402): undefined reference to _imp____glewUniformMatrix4fv' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x428): undefined reference to _imp____glewVertexAttribPointer' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x483): undefined reference to _imp____glewVertexAttribPointer' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x4c6): undefined reference to glEnable@4' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x4d5): undefined reference to glDepthFunc@4' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x4f4): undefined reference to glDrawArrays@12' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x4f9): undefined reference to _imp____glewDisableVertexAttribArray' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x50a): undefined reference to _imp____glewDisableVertexAttribArray' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x521): undefined reference to glfwSwapBuffers' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x526): undefined reference to glfwPollEvents' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x536): undefined reference to glfwGetKey' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x543): undefined reference to glfwWindowShouldClose' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x551): undefined reference to _imp____glewDeleteBuffers' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x588): undefined reference to _imp____glewDeleteProgram' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x5a3): undefined reference to _imp____glewDeleteVertexArrays' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x5ad): undefined reference to glfwTerminate' C:\Users\user\AppData\Local\Temp\cc3hmk5n.o:App.cpp:(.text.startup+0x642): undefined reference to glfwTerminate' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xbe): undefined reference to _imp____glewCreateShader' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xc72): undefined reference to _imp____glewShaderSource' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xc79): undefined reference to _imp____glewCompileShader' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xc87): undefined reference to _imp____glewGetShaderiv' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xd27): undefined reference to _imp____glewGetShaderInfoLog' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xd87): undefined reference to _imp____glewShaderSource' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xd8e): undefined reference to _imp____glewCompileShader' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xe24): undefined reference to _imp____glewGetShaderInfoLog' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xe4e): undefined reference to _imp____glewCreateProgram' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xe58): undefined reference to _imp____glewAttachShader' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xe7e): undefined reference to _imp____glewLinkProgram' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xe8c): undefined reference to _imp____glewGetProgramiv' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xeff): undefined reference to _imp____glewGetProgramInfoLog' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xf33): undefined reference to _imp____glewDetachShader' C:\Users\user\AppData\Local\Temp\cclIYxso.o:loadShader.cpp:(.text+0xf54): undefined reference to _imp____glewDeleteShader'
collect2.exe: error: ld returned 1 exit status

Azukitsu
  • 1
  • 1
  • 1
    You didn't actually specify any libraries to link. `-L` is only for the path to the directory containing libraries. The individual library files should be specified with `-l` flags, without file ending and without a `lib` prefix, e.g. `-lglfw`, probably also `-lglew` and `-lgl`. The order of these flags may be significant. – user17732522 Feb 06 '22 at 00:45
  • I tried to use the ```-l``` flag but it says it cannot find the file (in this case glfw). Originally, instead of the -L, I put -l, and after seeing it couldn't find it, I changed it to -L (thinking that they are the same). So how would I fix the issue of -l giving me the error of not finding the library? – Azukitsu Feb 06 '22 at 00:52
  • 1
    You need to figure out where the glfw library file is located, add the path to that file as `-L` argument and then add the `-lglfw` flag after that `-L` flag. – user17732522 Feb 06 '22 at 00:53
  • Oh sorry, I think I misunderstood at first. So the -L flag is simply to specify where Libraries may be found, and the -l is actually linking those libraries, by checking at the places where we said they might be using -L, right? Using the files inside the library files without the lib prefix and file ending, it gave me new errors. – Azukitsu Feb 06 '22 at 00:58
  • Warning: corrupt .drectve at end of def file Warning: corrupt .drectve at end of def file Warning: corrupt .drectve at end of def file Warning: corrupt .drectve at end of def file Warning: corrupt .drectve at end of def file Warning: corrupt .drectve at end of def file Warning: corrupt .drectve at end of def file Warning: corrupt .drectve at end of def file Warning: corrupt .drectve at end of def file Warning: corrupt .drectve at end of def file Warning: corrupt .drectve at end of def file A lot of these and then many others that are very similar to the ones I posted originally – Azukitsu Feb 06 '22 at 00:59
  • @Azukitsu It sounds like you've linked with the wrong library. Do you have `pkg-config` installed? – Ted Lyngmo Feb 06 '22 at 01:03
  • The naming of the path `lib-vc2022` seems to indicate that you downloaded/installed the library for Visual Studio/Visual C++ (vc). You should be using libraries compiled for MinGW. – user17732522 Feb 06 '22 at 01:07
  • @user17732522 Yeah I just noticed as well, so I tried changing the lib files to the mingw version, but it still gives me errors – Azukitsu Feb 06 '22 at 01:17
  • 1
    @TedLyngmo I don't have it installed, but It's possible that it is the wrong library – Azukitsu Feb 06 '22 at 01:17

0 Answers0