Hello world ends with ‘linker command failed’. g++, OpenGL, Macbook with m1 chip

  apple-m1, c++, g++, glfw, opengl

Macbook Air 2020, m1 chip, macOS 12.1 Monterey. No XCode. Though I have XCode Command Line tools.

I’m trying out OpenGL. I installed it: brew install glfw. I wrote this test.cpp:

#include <GLFW/glfw3.h>
int main(void)
{
    
    GLFWwindow* window;

    if (!glfwInit())
        return -1;

    return 0;

}

In Terminal, I run g++ -I/opt/homebrew/Cellar/glfw/3.3.6/include -o ./test ./test.cpp

And get this error: clang: error: linker command failed with exit code 1 (use -v to see invocation)

What should I do?

Source: Windows Questions C++

LEAVE A COMMENT