I am very new to c++ and I am trying to use opengl with glfw. I am using ubuntu 18 on wsl. I have GL and GLFW on my include directory and I have included it in my code.
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
using namespace glm;
int main(){
glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want OpenGL 3.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL
GLFWwindow* window; // (In the accompanying source code, this variable is global for simplicity)
window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
if( window == NULL ){
fprintf( stderr, "Hi\n" );
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window); // Initialize GLEW
glewExperimental=true; // Needed in core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return -1;
}
}
I am using g++ to compile the program. When I use g++ -c main.cpp it compiles but throws a binary error when I try to run the program and when I use g++ main.cpp -IGL -IGLFW -Iglm I get that error. Am I missing something?
Error:
/usr/bin/ld: /tmp/cco9YYTw.o: in function `main':
main.cpp:(.text+0x17): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.cpp:(.text+0x26): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.cpp:(.text+0x35): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.cpp:(.text+0x44): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.cpp:(.text+0x53): undefined reference to `glfwWindowHint'
/usr/bin/ld: main.cpp:(.text+0x74): undefined reference to `glfwCreateWindow'
/usr/bin/ld: main.cpp:(.text+0xa4): undefined reference to `glfwTerminate'
/usr/bin/ld: main.cpp:(.text+0xb7): undefined reference to `glfwMakeContextCurrent'
/usr/bin/ld: main.cpp:(.text+0xbd): undefined reference to `glewExperimental'
/usr/bin/ld: main.cpp:(.text+0xc3): undefined reference to `glewInit'
collect2: error: ld returned 1 exit status