Linking CMake with the OpenGL library and GLUT

I have written a C ++ project in which I am using the OpenGL and Glut libraries.

When I compile it from the command line everything works fine. Here's an example.

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 get the message: error: undefined reference to `glColor3f ' etc.

Can anyone help me?

+3


source to share


1 answer


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 shouldn't use the project name for the executable

+3


source







All Articles