This question already has an answer here:
I know this question has been asked already but the solutions provided really hasn't worked for me.
I want to run my OpenGL program via CLion IDE. I am able to run the same program via the terminal in Ubuntu using
$gcc progname.c -lglut -lGL -lGLU
but am unable to run the same in CLion
This is my CMakeLists.txt file
PS: I am using CLion in Ubuntu. Also there is no error in the program.
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.
For Linux (Ubuntu 16.04)
It should work for other Ubuntu versions too. Linux has made it easier to use OpenGL than Windows.
I am assuming that you can install OpenGL on Ubuntu. If you are facing problem with that,
Clion uses CMake for project files, and CMake makes it easy to link libraries that are in the system paths using
target_link_libraries
, which you can use in your case as shown below, which can come after theadd_executable
line:target_link_libraries(jarvis -lglut -lGL -lGLU)
The documentation for target_link_libraries is here: https://cmake.org/cmake/help/v3.3/command/target_link_libraries.html