Creating triangle /openGL/c++ /CMake

Can someone help why I get this error, im creating Triangle

 collect2: error: ld returned 1 exit status
 make[2]: *** [CMakeFiles/triangle.dir/build.make:108: triangle] Error 1
 make[1]: *** [CMakeFiles/Makefile2:164: CMakeFiles/triangle.dir/all] Error 2
 make: *** [Makefile:103: all] Error 2

her  is the CMakeLists.txt

   # Project definition
       cmake_minimum_required(VERSION 3.1)
      # Source files
      set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/source")
      set(LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries")
      set(SOURCES "${SRC_DIR}/main.cpp")
      # Executable definition and properties
      add_executable(${PROJECT_NAME} ${SOURCES})
      target_include_directories(${PROJECT_NAME} PRIVATE "${SRC_DIR}")
      # GLFW
      set(GLFW_DIR "${LIB_DIR}/glfw")
      set(GLFW_BUILD_EXAMPLES OFF CACHE INTERNAL "Build the GLFW example programs")
      set(GLFW_BUILD_TESTS OFF CACHE INTERNAL "Build the GLFW test programs")
      set(GLFW_BUILD_DOCS OFF CACHE INTERNAL "Build the GLFW documentation")
      set(GLFW_INSTALL OFF CACHE INTERNAL "Generate installation target")
      target_link_libraries(${PROJECT_NAME} "glfw" "${GLFW_LIBRARIES}")
      target_include_directories(${PROJECT_NAME} PRIVATE "${GLFW_DIR}/include")
      target_compile_definitions(${PROJECT_NAME} PRIVATE "GLFW_INCLUDE_NONE")
      # glad
      set(GLAD_DIR "${LIB_DIR}/glad")
      add_library("glad" "${GLAD_DIR}/src/glad.c")
      target_include_directories("glad" PRIVATE "${GLAD_DIR}/include")
     target_include_directories(${PROJECT_NAME} PRIVATE "${GLAD_DIR}/include")
     target_link_libraries(${PROJECT_NAME} "glad" "${CMAKE_DL_LIBS}")


here is the main.cpp

// A simple introductory program; its main window contains a static picture
// of a triangle, whose three vertices are red, green and blue.  The program
// illustrates viewing with default viewing parameters only.

#ifdef __APPLE_CC__
#include <GLUT/glut.h>
#include <GL/glut.h>

// Clears the current window and draws a triangle.
void display() {

  // Set every pixel in the frame buffer to the current clear color.

  // Drawing is done by specifying a sequence of vertices.  The way these
  // vertices are connected (or not connected) depends on the argument to
  // glBegin.  GL_POLYGON constructs a filled polygon.
    glColor3f(1, 0, 0); glVertex3f(-0.6, -0.75, 0.5);
    glColor3f(0, 1, 0); glVertex3f(0.6, -0.75, 0);
    glColor3f(0, 0, 1); glVertex3f(0, 0.75, 0);

  // Flush drawing command buffer to make drawing happen as soon as possible.

// Initializes GLUT, the display mode, and main window; registers callbacks;
// enters the main event loop.
int main(int argc, char** argv) {

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

  glutInitWindowPosition(80, 80);
  glutInitWindowSize(400, 300);
  glutCreateWindow("A Simple Triangle");


This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.