5

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?

2
  • 2
    Is this just a general "How do I link libraries in CLion" question? Commented Apr 4, 2017 at 10:53
  • quite similar to that. I have tried the instructions from this intellij-support.jetbrains.com/hc/en-us/articles/… but it's not working for me. Usually the library comes with many files but i want to use only these that's why i made separate directory and trying to add in clion. i don't understand what am I missing Commented Apr 4, 2017 at 11:05

3 Answers 3

9

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'.

For Windows

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)

For Linux (Ubuntu 16.04)

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

Sign up to request clarification or add additional context in comments.

Comments

2

I have fixed my problem by adding the following lines in the CMake file

include_directories(GL)

target_link_libraries(OpenGL GL/Glaux.lib GL/GLU32.LIB GL/glui32.lib GL/glut32.lib GL/OPENGL32.LIB)

Comments

0

this is a template: https://github.com/longshilin/Clion-OpenGL use clion to build opengl on Windows and MacOS.

CMakeLists.txt

cmake_minimum_required(VERSION 3.7)
project(Clion-OpenGL) # Your Project Name

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES OpenGL/src/Application.cpp)

include_directories(${PROJECT_SOURCE_DIR}/Dependencies/GLFW/include)
link_directories(${PROJECT_SOURCE_DIR}/Dependencies/GLFW/lib-vc2019)

include_directories(${PROJECT_SOURCE_DIR}/Dependencies/GLEW/include)
link_directories(${PROJECT_SOURCE_DIR}/Dependencies/GLEW/lib/Release/Win32)

add_definitions(-DGLEW_STATIC)

add_executable(Clion-OpenGL ${SOURCE_FILES})
target_link_libraries(Clion-OpenGL glew32s glfw3 opengl32 User32 Gdi32 Shell32)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.