Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake linking OpenGL and GLUT library [duplicate]

Tags:

cmake

opengl

glut

I wrote c++ project in which I am using OpenGL and Glut library.

When I compile it from command line everything works fine. Here is sample.

g++ -o prog source.cpp -lGL -lGLU -lglut --std=c++11 -L /usr/lib/nvidia-331/

But when I want to use CMake in QtCreator:

project(proj)
cmake_minimum_required(VERSION 2.8)

aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lGL -lGLU -lglut -L /usr/lib/nvidia-331/") 

I recieve msg: error: undefined reference to `glColor3f' and so on.

Can anybody help me?

like image 507
Bender Avatar asked Nov 06 '14 09:11

Bender


1 Answers

project(proj)
cmake_minimum_required(VERSION 2.8)

find_package(OpenGL)
find_package(GLUT)

aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(
    ${PROJECT_NAME}
    ${OPENGL_gl_LIBRARY}
    ${GLUT_LIBRARIES} )

Note: You should not use the project name for the executable

like image 170
datenwolf Avatar answered Sep 30 '22 09:09

datenwolf