How to compile GLUT + OpenGL project with CMake and Kdevelop in linux?

前端 未结 3 677
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 23:32

As the titles says I can\'t seem to build the project with OpenGL and Glut.

I get Undefined reference errors for OpenGL functions.

I tried doing :

         


        
3条回答
  •  孤街浪徒
    2020-12-05 00:17

    In recent versions of CMake (3.10+) there is a new way to use OpenGL using a so-called IMPORTED target:

    cmake_minimum_required(VERSION 3.10)
    
    project(testas)
    add_executable(testas main.cpp)
    find_package(OpenGL REQUIRED COMPONENTS OpenGL)
    find_package(GLUT REQUIRED)
    
    add_dependencies(testas OpenGL::OpenGL)
    include_directories(${GLUT_INCLUDE_DIRS} )
    
    target_link_libraries(testas OpenGL::OpenGL ${GLUT_LIBRARY} )
    

    At the moment the only practical difference seems to be on Linux (where GLVND is used if available), but presumably this solution should be more future-proof, as CMake has more information about your intentions and other tools parsing your CMakeFiles will better understand the dependency tree.

提交回复
热议问题