I am trying to compile a c++ file on command line with g++
i have this file
#include <iostream>
#include "C:\Users\Shaurya\Documents\Opengl\Dependencies\GLFW\include\GLFW\glfw3.h"
using namespace std;
int main(){
GLFWwindow* window;
if(!glfwInit()){
cout << "Window not initialized";
return -1;
}
window = glfwCreateWindow(600,600,"OpenGL", NULL, NULL);
if(!window){
cout << "Window Not created";
glfwTerminate();
}
glfwMakeContextCurrent(window);
while(glfwWindowShouldClose(window)){
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
I run this command
g++ -o Test main.cpp -L <fullpath>\Dependencies\GLFW\lib-vc2019 -lglfw3.lib
but this throws a gigantic error
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: mode i386pe
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../crt2.o
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/crtbegin.o
C:\Users\Shaurya\AppData\Local\Temp\ccxDP2Km.o
(c:/mingw/bin/../lib/gcc/mingw32/6.3.0/libstdc++.dll.a)d004332.o
.
.
(c:/mingw/bin/../lib/gcc/mingw32/6.3.0/libgcc_s.a)d000122.o
(c:/mingw/bin/../lib/gcc/mingw32/6.3.0/libgcc.a)_chkstk_ms.o
(c:/mingw/bin/../lib/gcc/mingw32/6.3.0/libgcc.a)_ctors.o
(c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingwex.a)fesetenv.o
.
.
.
(c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmoldname.a)dagwbt.o
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/crtend.o
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lglfw3.lib
collect2.exe: error: ld returned 1 exit status
It took me alot of time to realize that the -l
is only looking for .o
files
So how do i link with .lib files? i got the .lib from glfw.org binaries.
I dont want to use Visual Studio 2019 to do this because my laptop has a hard time running that.
So i solved this. First i was using the wrong libraries. I was provided with multiple versions of Libraries and i was using VC version. But when i used MinGW Version , it worked.
Moreover , i was using relative paths without typing ./
before them.