I have a folder named GL
containing following files:
---glu32.dll
---GLAux.h
---OPENGL32.LIB
---glut32.lib
---glut.h
---GL.H
---glui.h
---glui32.lib
---glut32.dll
---GLU32.LIB
---Glaux.lib
---GLU.H
---opengl32.dll
I have worked with these files in Visual Studio but I am new to CLion that's why don't know how the linking directory works through CMake. How can I use the liraries in CLion?
I have made it work in both Windows 10 and Linux (Ubuntu 16.04) after a lot of searching on Google. Apparently it's not so easy to find after all. So, I am gonna put an end to this problem now and here.
Here, I am going to show you how to configure the CMakeLists.txt file to compile a OpenGL program which is the main challenge here. I am assuming that you can write basic OpenGL programs and you have written a file named 'demoMain.cpp'.
I am assuming you can setup OpenGL on windows. If you can't, there are plenty of tutorials on youtube and StackOverflow. After that, continue.
cmake_minimum_required(VERSION 3.10)
project(Graphics_Offline_1) # Your Project Name
set(CMAKE_CXX_STANDARD 11)
include_directories(OpenGL)
include_directories(OpenGL/include) # OpenGL/include has to contain the required OpenGL's .h files
include_directories(OpenGL/lib) # OpenGL/lib has to contain the required OpenGL's .lib files
# glut32.dll must be present in "project-directory/OpenGL/dll/"
add_custom_target(glutdlllib
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/OpenGL/dll/glut32.dll ${CMAKE_BINARY_DIR}
)
# required .lib files to be copied into compiler's proper directory
set(OpenGlLibs glaux glu32 glui32 glut32 opengl32)
#These 3 lines are just linking and making executables
add_executable(demo demoMain.cpp)
target_link_libraries(demo ${OpenGlLibs})
add_dependencies(demo glutdlllib)
It should work for other Ubuntu versions too. Linux has made it easier to use OpenGL than Windows.
cmake_minimum_required(VERSION 3.10) # common to every CLion project
project(OpenGLLinuxTest) # project name
set(OpenGlLinkers -lglut -lGLU -lGL) # setting all the Glut libraries as one variable.
################################################
add_executable(OpenGLLinuxTest1 main.cpp ) #common to all clion project
target_link_libraries(OpenGLLinuxTest1 ${OpenGlLinkers}) # linking opengl libraries to the project
#################################################
I am assuming that you can install OpenGL on Ubuntu. If you are facing problem with that,
follow this link - http://www.codebind.com/linux-tutorials/install-opengl-ubuntu-linux/ . If this is not working, follow this one - https://gist.github.com/shamiul94/a632f7ab94cf389e08efd7174335df1c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With