0

here is the code:

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

int main()
{
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    
    GLFWwindow* window = glfwCreateWindow(800, 800, "YoutubeOpenGL", NULL, NULL);

    if (window == NULL)
    {
        std::cout<< "Failed to create GLFW window"<<std::endl;
        glfwTerminate();
        return -1;
    } 

    glfwMakeContextCurrent(window);

    gladLoadGL();

    glViewport(0, 0, 800,800);  //area where things are rendered
    glClearColor(0.07f,0.13f,0.17f,1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glfwSwapBuffers(window);

    while(!glfwWindowShouldClose(window))
    { 
        glfwPollEvents();
    }

    glfwDestroyWindow(window);
    glfwTerminate();
    return 0;
}

I tried a very basic one: g++ -o GameWindow Main.cpp

and I got this output in the terminal:

(base) alon@pop-os-alon:~/Documents/asteroids$ g++ -o GameWindow Main.cpp
/usr/bin/ld: /tmp/cc0qAMFd.o: warning: relocation against `glad_glClearColor' in read-only section `.text'
/usr/bin/ld: /tmp/cc0qAMFd.o: in function `main':
Main.cpp:(.text+0xd): undefined reference to `glfwInit'
/usr/bin/ld: Main.cpp:(.text+0x1c): undefined reference to `glfwWindowHint'
/usr/bin/ld: Main.cpp:(.text+0x2b): undefined reference to `glfwWindowHint'
/usr/bin/ld: Main.cpp:(.text+0x3a): undefined reference to `glfwWindowHint'
/usr/bin/ld: Main.cpp:(.text+0x5e): undefined reference to `glfwCreateWindow'
/usr/bin/ld: Main.cpp:(.text+0x99): undefined reference to `glfwTerminate'
/usr/bin/ld: Main.cpp:(.text+0xaf): undefined reference to `glfwMakeContextCurrent'
/usr/bin/ld: Main.cpp:(.text+0xb4): undefined reference to `gladLoadGL'
/usr/bin/ld: Main.cpp:(.text+0xbb): undefined reference to `glad_glViewport'
/usr/bin/ld: Main.cpp:(.text+0xd8): undefined reference to `glad_glClearColor'
/usr/bin/ld: Main.cpp:(.text+0x103): undefined reference to `glad_glClear'
/usr/bin/ld: Main.cpp:(.text+0x116): undefined reference to `glfwSwapBuffers'
/usr/bin/ld: Main.cpp:(.text+0x11d): undefined reference to `glfwPollEvents'
/usr/bin/ld: Main.cpp:(.text+0x129): undefined reference to `glfwWindowShouldClose'
/usr/bin/ld: Main.cpp:(.text+0x13e): undefined reference to `glfwDestroyWindow'
/usr/bin/ld: Main.cpp:(.text+0x143): undefined reference to `glfwTerminate'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
genpfault
  • 49,394
  • 10
  • 79
  • 128
Angie
  • 1
  • FYI: [LearnOpenGL](https://learnopengl.com/) recommends [Glitter](https://github.com/Polytonic/Glitter) for a quick start. Btw. _I'm a bit rusty with my c++._ That's hard to believe. It's an essential fact for C++ (as well as C) that nearly everything isn't part of the language but comes out of libraries you have to link your application against. If you missed that you never really did C++... ;-) – Scheff's Cat Mar 10 '22 at 10:43

0 Answers0