How to compile GLUT + OpenGL project with CMake and Kdevelop in linux?
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 :
project(testas)
find_package(OpenGL)
find_package(GLUT)
add_executable(testas main.cpp)
But that doesn't work.
Any suggestions?
linux opengl cmake
add a comment |
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 :
project(testas)
find_package(OpenGL)
find_package(GLUT)
add_executable(testas main.cpp)
But that doesn't work.
Any suggestions?
linux opengl cmake
add a comment |
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 :
project(testas)
find_package(OpenGL)
find_package(GLUT)
add_executable(testas main.cpp)
But that doesn't work.
Any suggestions?
linux opengl cmake
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 :
project(testas)
find_package(OpenGL)
find_package(GLUT)
add_executable(testas main.cpp)
But that doesn't work.
Any suggestions?
linux opengl cmake
linux opengl cmake
asked Feb 27 '12 at 4:58
Ren
3111512
3111512
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
find_package(OpenGL)
will find the package for you, but it doesn't link the package to the target.
To link to a library, you can use target_link_libraries(<target> <item>)
. In addition, you also need to set the include directory
, so that the linker knows where to look for things. This is done with the include_directories
.
An example CMakeLists.txt
which would do this looks something like this:
cmake_minimum_required(VERSION 2.8)
project(testas)
add_executable(testas main.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} )
target_link_libraries(testas ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} )
If OpenGL
is a necessity for your project, you might consider either testing OpenGL_FOUND
after the find_package(OpenGL)
or using REQUIRED
, which will stop cmake
if OpenGL
is not found.
For more information and better examples:
- CMake 2.8 documentation, target_link_libraries
- CMake 2.8 documentation, find_package
- CMake wiki: how to find libraries
- Forum post with solution: cmake and opengl
- Tutorial for CMake by swarthmore.edu
In particular, the CMake wiki
and cmake and opengl
links should give you enough to get things working.
Thanks for an answer. Now I'm getting error that it doesn't find them, I did install them./usr/bin/ld: error: cannot find -lOpenGL /usr/bin/ld: error: cannot find -lGLUT
– Ren
Feb 27 '12 at 19:14
Whoops, mis-typed thetarget_link_libraries
in the answer. Fixed it now, and checked that it works. :)
– simont
Feb 27 '12 at 19:35
Sadly, this is the build log pastebin.com/cRp5xPYD
– Ren
Feb 27 '12 at 19:46
I take it that there's no issue linking toOpenGL
orGLUT
, then? That kind of error suggests thatGLUT_Xi
andGLUT_Xmu
are not installed (they weren't found bycmake
). If you're on Ubuntu, check this link. If not, try installingGLUT_Xi
andGLUT_Xmu
for your system.
– simont
Feb 27 '12 at 19:52
Thanks! That removed those.. but one more problem persists, will you able to help me this time too ? pastebin.com/EekEQyfs I feel hopeless.
– Ren
Feb 27 '12 at 19:55
|
show 7 more comments
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.
add a comment |
I use these two cmake files to build my OpenGL projects, and they all work well.
I only test these two cmake files under Deepin Linux. Deepin Linux is a Chinese grown Linux system like Ubuntu or from Debian.
First, the main CMakeLists.txt
cmake_minimum_required(VERSION 3.1.0)
project(project_name)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/")
find_package(OpenGL REQUIRED)
find_package(FREEGLUT REQUIRED)
find_package(GLEW REQUIRED)
if(NOT ${OPENGL_FOUND})
message("OPENGL not found")
endif()
include_directories(
${PROJECT_SOURCE_DIR}
${FREEGLUT_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
)
message(${OPENGL_INCLUDE_DIR})
add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/filename.cpp)
target_link_libraries(${PROJECT_NAME}
${OPENGL_LIBRARY}
${FREEGLUT_LIBRARY}
${GLEW_LIBRARY}
)
Second, the find GLUT cmake file under CMakeModules directory
# Try to find the FREEGLUT library
#
# FREEGLUT_INCLUDE_DIR
# FREEGLUT_LIBRARY
# FREEGLUT_FOUND
FIND_PATH(
FREEGLUT_INCLUDE_DIR GL/freeglut.h GL/gl.h GL/glu.h GL/glew.h
${CMAKE_INCLUDE_PATH}
$ENV{include}
${OPENGL_INCLUDE_DIR}
/usr/include
/usr/local/include
)
SET(STORE_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
SET(CMAKE_FIND_FRAMEWORK NEVER)
FIND_LIBRARY(
FREEGLUT_LIBRARY
NAMES freeglut_static freeglut glut GL
PATH
/opt/local/lib
${CMAKE_LIBRARY_PATH}
$ENV{lib}
/usr/lib
/usr/local/lib
)
SET(CMAKE_FIND_FRAMEWORK ${STORE_CMAKE_FIND_FRAMEWORK})
IF (FREEGLUT_INCLUDE_DIR AND FREEGLUT_LIBRARY)
SET(FREEGLUT_FOUND TRUE)
ENDIF (FREEGLUT_INCLUDE_DIR AND FREEGLUT_LIBRARY)
IF (FREEGLUT_FOUND)
IF (NOT FREEGLUT_FIND_QUIETLY)
MESSAGE(STATUS "Found FREEGLUT: ${FREEGLUT_LIBRARY}")
ENDIF (NOT FREEGLUT_FIND_QUIETLY)
ELSE (FREEGLUT_FOUND)
IF (FREEGLUT_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find FREEGLUT")
ENDIF (FREEGLUT_FIND_REQUIRED)
ENDIF (FREEGLUT_FOUND)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f9460242%2fhow-to-compile-glut-opengl-project-with-cmake-and-kdevelop-in-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
find_package(OpenGL)
will find the package for you, but it doesn't link the package to the target.
To link to a library, you can use target_link_libraries(<target> <item>)
. In addition, you also need to set the include directory
, so that the linker knows where to look for things. This is done with the include_directories
.
An example CMakeLists.txt
which would do this looks something like this:
cmake_minimum_required(VERSION 2.8)
project(testas)
add_executable(testas main.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} )
target_link_libraries(testas ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} )
If OpenGL
is a necessity for your project, you might consider either testing OpenGL_FOUND
after the find_package(OpenGL)
or using REQUIRED
, which will stop cmake
if OpenGL
is not found.
For more information and better examples:
- CMake 2.8 documentation, target_link_libraries
- CMake 2.8 documentation, find_package
- CMake wiki: how to find libraries
- Forum post with solution: cmake and opengl
- Tutorial for CMake by swarthmore.edu
In particular, the CMake wiki
and cmake and opengl
links should give you enough to get things working.
Thanks for an answer. Now I'm getting error that it doesn't find them, I did install them./usr/bin/ld: error: cannot find -lOpenGL /usr/bin/ld: error: cannot find -lGLUT
– Ren
Feb 27 '12 at 19:14
Whoops, mis-typed thetarget_link_libraries
in the answer. Fixed it now, and checked that it works. :)
– simont
Feb 27 '12 at 19:35
Sadly, this is the build log pastebin.com/cRp5xPYD
– Ren
Feb 27 '12 at 19:46
I take it that there's no issue linking toOpenGL
orGLUT
, then? That kind of error suggests thatGLUT_Xi
andGLUT_Xmu
are not installed (they weren't found bycmake
). If you're on Ubuntu, check this link. If not, try installingGLUT_Xi
andGLUT_Xmu
for your system.
– simont
Feb 27 '12 at 19:52
Thanks! That removed those.. but one more problem persists, will you able to help me this time too ? pastebin.com/EekEQyfs I feel hopeless.
– Ren
Feb 27 '12 at 19:55
|
show 7 more comments
find_package(OpenGL)
will find the package for you, but it doesn't link the package to the target.
To link to a library, you can use target_link_libraries(<target> <item>)
. In addition, you also need to set the include directory
, so that the linker knows where to look for things. This is done with the include_directories
.
An example CMakeLists.txt
which would do this looks something like this:
cmake_minimum_required(VERSION 2.8)
project(testas)
add_executable(testas main.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} )
target_link_libraries(testas ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} )
If OpenGL
is a necessity for your project, you might consider either testing OpenGL_FOUND
after the find_package(OpenGL)
or using REQUIRED
, which will stop cmake
if OpenGL
is not found.
For more information and better examples:
- CMake 2.8 documentation, target_link_libraries
- CMake 2.8 documentation, find_package
- CMake wiki: how to find libraries
- Forum post with solution: cmake and opengl
- Tutorial for CMake by swarthmore.edu
In particular, the CMake wiki
and cmake and opengl
links should give you enough to get things working.
Thanks for an answer. Now I'm getting error that it doesn't find them, I did install them./usr/bin/ld: error: cannot find -lOpenGL /usr/bin/ld: error: cannot find -lGLUT
– Ren
Feb 27 '12 at 19:14
Whoops, mis-typed thetarget_link_libraries
in the answer. Fixed it now, and checked that it works. :)
– simont
Feb 27 '12 at 19:35
Sadly, this is the build log pastebin.com/cRp5xPYD
– Ren
Feb 27 '12 at 19:46
I take it that there's no issue linking toOpenGL
orGLUT
, then? That kind of error suggests thatGLUT_Xi
andGLUT_Xmu
are not installed (they weren't found bycmake
). If you're on Ubuntu, check this link. If not, try installingGLUT_Xi
andGLUT_Xmu
for your system.
– simont
Feb 27 '12 at 19:52
Thanks! That removed those.. but one more problem persists, will you able to help me this time too ? pastebin.com/EekEQyfs I feel hopeless.
– Ren
Feb 27 '12 at 19:55
|
show 7 more comments
find_package(OpenGL)
will find the package for you, but it doesn't link the package to the target.
To link to a library, you can use target_link_libraries(<target> <item>)
. In addition, you also need to set the include directory
, so that the linker knows where to look for things. This is done with the include_directories
.
An example CMakeLists.txt
which would do this looks something like this:
cmake_minimum_required(VERSION 2.8)
project(testas)
add_executable(testas main.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} )
target_link_libraries(testas ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} )
If OpenGL
is a necessity for your project, you might consider either testing OpenGL_FOUND
after the find_package(OpenGL)
or using REQUIRED
, which will stop cmake
if OpenGL
is not found.
For more information and better examples:
- CMake 2.8 documentation, target_link_libraries
- CMake 2.8 documentation, find_package
- CMake wiki: how to find libraries
- Forum post with solution: cmake and opengl
- Tutorial for CMake by swarthmore.edu
In particular, the CMake wiki
and cmake and opengl
links should give you enough to get things working.
find_package(OpenGL)
will find the package for you, but it doesn't link the package to the target.
To link to a library, you can use target_link_libraries(<target> <item>)
. In addition, you also need to set the include directory
, so that the linker knows where to look for things. This is done with the include_directories
.
An example CMakeLists.txt
which would do this looks something like this:
cmake_minimum_required(VERSION 2.8)
project(testas)
add_executable(testas main.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} )
target_link_libraries(testas ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} )
If OpenGL
is a necessity for your project, you might consider either testing OpenGL_FOUND
after the find_package(OpenGL)
or using REQUIRED
, which will stop cmake
if OpenGL
is not found.
For more information and better examples:
- CMake 2.8 documentation, target_link_libraries
- CMake 2.8 documentation, find_package
- CMake wiki: how to find libraries
- Forum post with solution: cmake and opengl
- Tutorial for CMake by swarthmore.edu
In particular, the CMake wiki
and cmake and opengl
links should give you enough to get things working.
edited Dec 4 '17 at 11:45


SteScheller
808
808
answered Feb 27 '12 at 17:27
simont
38.6k1397120
38.6k1397120
Thanks for an answer. Now I'm getting error that it doesn't find them, I did install them./usr/bin/ld: error: cannot find -lOpenGL /usr/bin/ld: error: cannot find -lGLUT
– Ren
Feb 27 '12 at 19:14
Whoops, mis-typed thetarget_link_libraries
in the answer. Fixed it now, and checked that it works. :)
– simont
Feb 27 '12 at 19:35
Sadly, this is the build log pastebin.com/cRp5xPYD
– Ren
Feb 27 '12 at 19:46
I take it that there's no issue linking toOpenGL
orGLUT
, then? That kind of error suggests thatGLUT_Xi
andGLUT_Xmu
are not installed (they weren't found bycmake
). If you're on Ubuntu, check this link. If not, try installingGLUT_Xi
andGLUT_Xmu
for your system.
– simont
Feb 27 '12 at 19:52
Thanks! That removed those.. but one more problem persists, will you able to help me this time too ? pastebin.com/EekEQyfs I feel hopeless.
– Ren
Feb 27 '12 at 19:55
|
show 7 more comments
Thanks for an answer. Now I'm getting error that it doesn't find them, I did install them./usr/bin/ld: error: cannot find -lOpenGL /usr/bin/ld: error: cannot find -lGLUT
– Ren
Feb 27 '12 at 19:14
Whoops, mis-typed thetarget_link_libraries
in the answer. Fixed it now, and checked that it works. :)
– simont
Feb 27 '12 at 19:35
Sadly, this is the build log pastebin.com/cRp5xPYD
– Ren
Feb 27 '12 at 19:46
I take it that there's no issue linking toOpenGL
orGLUT
, then? That kind of error suggests thatGLUT_Xi
andGLUT_Xmu
are not installed (they weren't found bycmake
). If you're on Ubuntu, check this link. If not, try installingGLUT_Xi
andGLUT_Xmu
for your system.
– simont
Feb 27 '12 at 19:52
Thanks! That removed those.. but one more problem persists, will you able to help me this time too ? pastebin.com/EekEQyfs I feel hopeless.
– Ren
Feb 27 '12 at 19:55
Thanks for an answer. Now I'm getting error that it doesn't find them, I did install them.
/usr/bin/ld: error: cannot find -lOpenGL /usr/bin/ld: error: cannot find -lGLUT
– Ren
Feb 27 '12 at 19:14
Thanks for an answer. Now I'm getting error that it doesn't find them, I did install them.
/usr/bin/ld: error: cannot find -lOpenGL /usr/bin/ld: error: cannot find -lGLUT
– Ren
Feb 27 '12 at 19:14
Whoops, mis-typed the
target_link_libraries
in the answer. Fixed it now, and checked that it works. :)– simont
Feb 27 '12 at 19:35
Whoops, mis-typed the
target_link_libraries
in the answer. Fixed it now, and checked that it works. :)– simont
Feb 27 '12 at 19:35
Sadly, this is the build log pastebin.com/cRp5xPYD
– Ren
Feb 27 '12 at 19:46
Sadly, this is the build log pastebin.com/cRp5xPYD
– Ren
Feb 27 '12 at 19:46
I take it that there's no issue linking to
OpenGL
or GLUT
, then? That kind of error suggests that GLUT_Xi
and GLUT_Xmu
are not installed (they weren't found by cmake
). If you're on Ubuntu, check this link. If not, try installing GLUT_Xi
and GLUT_Xmu
for your system.– simont
Feb 27 '12 at 19:52
I take it that there's no issue linking to
OpenGL
or GLUT
, then? That kind of error suggests that GLUT_Xi
and GLUT_Xmu
are not installed (they weren't found by cmake
). If you're on Ubuntu, check this link. If not, try installing GLUT_Xi
and GLUT_Xmu
for your system.– simont
Feb 27 '12 at 19:52
Thanks! That removed those.. but one more problem persists, will you able to help me this time too ? pastebin.com/EekEQyfs I feel hopeless.
– Ren
Feb 27 '12 at 19:55
Thanks! That removed those.. but one more problem persists, will you able to help me this time too ? pastebin.com/EekEQyfs I feel hopeless.
– Ren
Feb 27 '12 at 19:55
|
show 7 more comments
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 19 '18 at 16:10
minexew
360210
360210
add a comment |
add a comment |
I use these two cmake files to build my OpenGL projects, and they all work well.
I only test these two cmake files under Deepin Linux. Deepin Linux is a Chinese grown Linux system like Ubuntu or from Debian.
First, the main CMakeLists.txt
cmake_minimum_required(VERSION 3.1.0)
project(project_name)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/")
find_package(OpenGL REQUIRED)
find_package(FREEGLUT REQUIRED)
find_package(GLEW REQUIRED)
if(NOT ${OPENGL_FOUND})
message("OPENGL not found")
endif()
include_directories(
${PROJECT_SOURCE_DIR}
${FREEGLUT_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
)
message(${OPENGL_INCLUDE_DIR})
add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/filename.cpp)
target_link_libraries(${PROJECT_NAME}
${OPENGL_LIBRARY}
${FREEGLUT_LIBRARY}
${GLEW_LIBRARY}
)
Second, the find GLUT cmake file under CMakeModules directory
# Try to find the FREEGLUT library
#
# FREEGLUT_INCLUDE_DIR
# FREEGLUT_LIBRARY
# FREEGLUT_FOUND
FIND_PATH(
FREEGLUT_INCLUDE_DIR GL/freeglut.h GL/gl.h GL/glu.h GL/glew.h
${CMAKE_INCLUDE_PATH}
$ENV{include}
${OPENGL_INCLUDE_DIR}
/usr/include
/usr/local/include
)
SET(STORE_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
SET(CMAKE_FIND_FRAMEWORK NEVER)
FIND_LIBRARY(
FREEGLUT_LIBRARY
NAMES freeglut_static freeglut glut GL
PATH
/opt/local/lib
${CMAKE_LIBRARY_PATH}
$ENV{lib}
/usr/lib
/usr/local/lib
)
SET(CMAKE_FIND_FRAMEWORK ${STORE_CMAKE_FIND_FRAMEWORK})
IF (FREEGLUT_INCLUDE_DIR AND FREEGLUT_LIBRARY)
SET(FREEGLUT_FOUND TRUE)
ENDIF (FREEGLUT_INCLUDE_DIR AND FREEGLUT_LIBRARY)
IF (FREEGLUT_FOUND)
IF (NOT FREEGLUT_FIND_QUIETLY)
MESSAGE(STATUS "Found FREEGLUT: ${FREEGLUT_LIBRARY}")
ENDIF (NOT FREEGLUT_FIND_QUIETLY)
ELSE (FREEGLUT_FOUND)
IF (FREEGLUT_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find FREEGLUT")
ENDIF (FREEGLUT_FIND_REQUIRED)
ENDIF (FREEGLUT_FOUND)
add a comment |
I use these two cmake files to build my OpenGL projects, and they all work well.
I only test these two cmake files under Deepin Linux. Deepin Linux is a Chinese grown Linux system like Ubuntu or from Debian.
First, the main CMakeLists.txt
cmake_minimum_required(VERSION 3.1.0)
project(project_name)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/")
find_package(OpenGL REQUIRED)
find_package(FREEGLUT REQUIRED)
find_package(GLEW REQUIRED)
if(NOT ${OPENGL_FOUND})
message("OPENGL not found")
endif()
include_directories(
${PROJECT_SOURCE_DIR}
${FREEGLUT_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
)
message(${OPENGL_INCLUDE_DIR})
add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/filename.cpp)
target_link_libraries(${PROJECT_NAME}
${OPENGL_LIBRARY}
${FREEGLUT_LIBRARY}
${GLEW_LIBRARY}
)
Second, the find GLUT cmake file under CMakeModules directory
# Try to find the FREEGLUT library
#
# FREEGLUT_INCLUDE_DIR
# FREEGLUT_LIBRARY
# FREEGLUT_FOUND
FIND_PATH(
FREEGLUT_INCLUDE_DIR GL/freeglut.h GL/gl.h GL/glu.h GL/glew.h
${CMAKE_INCLUDE_PATH}
$ENV{include}
${OPENGL_INCLUDE_DIR}
/usr/include
/usr/local/include
)
SET(STORE_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
SET(CMAKE_FIND_FRAMEWORK NEVER)
FIND_LIBRARY(
FREEGLUT_LIBRARY
NAMES freeglut_static freeglut glut GL
PATH
/opt/local/lib
${CMAKE_LIBRARY_PATH}
$ENV{lib}
/usr/lib
/usr/local/lib
)
SET(CMAKE_FIND_FRAMEWORK ${STORE_CMAKE_FIND_FRAMEWORK})
IF (FREEGLUT_INCLUDE_DIR AND FREEGLUT_LIBRARY)
SET(FREEGLUT_FOUND TRUE)
ENDIF (FREEGLUT_INCLUDE_DIR AND FREEGLUT_LIBRARY)
IF (FREEGLUT_FOUND)
IF (NOT FREEGLUT_FIND_QUIETLY)
MESSAGE(STATUS "Found FREEGLUT: ${FREEGLUT_LIBRARY}")
ENDIF (NOT FREEGLUT_FIND_QUIETLY)
ELSE (FREEGLUT_FOUND)
IF (FREEGLUT_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find FREEGLUT")
ENDIF (FREEGLUT_FIND_REQUIRED)
ENDIF (FREEGLUT_FOUND)
add a comment |
I use these two cmake files to build my OpenGL projects, and they all work well.
I only test these two cmake files under Deepin Linux. Deepin Linux is a Chinese grown Linux system like Ubuntu or from Debian.
First, the main CMakeLists.txt
cmake_minimum_required(VERSION 3.1.0)
project(project_name)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/")
find_package(OpenGL REQUIRED)
find_package(FREEGLUT REQUIRED)
find_package(GLEW REQUIRED)
if(NOT ${OPENGL_FOUND})
message("OPENGL not found")
endif()
include_directories(
${PROJECT_SOURCE_DIR}
${FREEGLUT_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
)
message(${OPENGL_INCLUDE_DIR})
add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/filename.cpp)
target_link_libraries(${PROJECT_NAME}
${OPENGL_LIBRARY}
${FREEGLUT_LIBRARY}
${GLEW_LIBRARY}
)
Second, the find GLUT cmake file under CMakeModules directory
# Try to find the FREEGLUT library
#
# FREEGLUT_INCLUDE_DIR
# FREEGLUT_LIBRARY
# FREEGLUT_FOUND
FIND_PATH(
FREEGLUT_INCLUDE_DIR GL/freeglut.h GL/gl.h GL/glu.h GL/glew.h
${CMAKE_INCLUDE_PATH}
$ENV{include}
${OPENGL_INCLUDE_DIR}
/usr/include
/usr/local/include
)
SET(STORE_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
SET(CMAKE_FIND_FRAMEWORK NEVER)
FIND_LIBRARY(
FREEGLUT_LIBRARY
NAMES freeglut_static freeglut glut GL
PATH
/opt/local/lib
${CMAKE_LIBRARY_PATH}
$ENV{lib}
/usr/lib
/usr/local/lib
)
SET(CMAKE_FIND_FRAMEWORK ${STORE_CMAKE_FIND_FRAMEWORK})
IF (FREEGLUT_INCLUDE_DIR AND FREEGLUT_LIBRARY)
SET(FREEGLUT_FOUND TRUE)
ENDIF (FREEGLUT_INCLUDE_DIR AND FREEGLUT_LIBRARY)
IF (FREEGLUT_FOUND)
IF (NOT FREEGLUT_FIND_QUIETLY)
MESSAGE(STATUS "Found FREEGLUT: ${FREEGLUT_LIBRARY}")
ENDIF (NOT FREEGLUT_FIND_QUIETLY)
ELSE (FREEGLUT_FOUND)
IF (FREEGLUT_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find FREEGLUT")
ENDIF (FREEGLUT_FIND_REQUIRED)
ENDIF (FREEGLUT_FOUND)
I use these two cmake files to build my OpenGL projects, and they all work well.
I only test these two cmake files under Deepin Linux. Deepin Linux is a Chinese grown Linux system like Ubuntu or from Debian.
First, the main CMakeLists.txt
cmake_minimum_required(VERSION 3.1.0)
project(project_name)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/")
find_package(OpenGL REQUIRED)
find_package(FREEGLUT REQUIRED)
find_package(GLEW REQUIRED)
if(NOT ${OPENGL_FOUND})
message("OPENGL not found")
endif()
include_directories(
${PROJECT_SOURCE_DIR}
${FREEGLUT_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
)
message(${OPENGL_INCLUDE_DIR})
add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/filename.cpp)
target_link_libraries(${PROJECT_NAME}
${OPENGL_LIBRARY}
${FREEGLUT_LIBRARY}
${GLEW_LIBRARY}
)
Second, the find GLUT cmake file under CMakeModules directory
# Try to find the FREEGLUT library
#
# FREEGLUT_INCLUDE_DIR
# FREEGLUT_LIBRARY
# FREEGLUT_FOUND
FIND_PATH(
FREEGLUT_INCLUDE_DIR GL/freeglut.h GL/gl.h GL/glu.h GL/glew.h
${CMAKE_INCLUDE_PATH}
$ENV{include}
${OPENGL_INCLUDE_DIR}
/usr/include
/usr/local/include
)
SET(STORE_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
SET(CMAKE_FIND_FRAMEWORK NEVER)
FIND_LIBRARY(
FREEGLUT_LIBRARY
NAMES freeglut_static freeglut glut GL
PATH
/opt/local/lib
${CMAKE_LIBRARY_PATH}
$ENV{lib}
/usr/lib
/usr/local/lib
)
SET(CMAKE_FIND_FRAMEWORK ${STORE_CMAKE_FIND_FRAMEWORK})
IF (FREEGLUT_INCLUDE_DIR AND FREEGLUT_LIBRARY)
SET(FREEGLUT_FOUND TRUE)
ENDIF (FREEGLUT_INCLUDE_DIR AND FREEGLUT_LIBRARY)
IF (FREEGLUT_FOUND)
IF (NOT FREEGLUT_FIND_QUIETLY)
MESSAGE(STATUS "Found FREEGLUT: ${FREEGLUT_LIBRARY}")
ENDIF (NOT FREEGLUT_FIND_QUIETLY)
ELSE (FREEGLUT_FOUND)
IF (FREEGLUT_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find FREEGLUT")
ENDIF (FREEGLUT_FIND_REQUIRED)
ENDIF (FREEGLUT_FOUND)
answered Aug 14 '17 at 9:09


wangzheqie
185
185
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f9460242%2fhow-to-compile-glut-opengl-project-with-cmake-and-kdevelop-in-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown