Kyu96
Kyu96

Reputation: 1349

CLion compile glut linux

I am trying to compile a C++ project on linux which utilizes freeglut. I can not build the project because the libraries are not linked correctly in the CMake files. I researched and tried to apply what was mentioned in a similar answer here: How to compile GLUT + OpenGL project with CMake and Kdevelop in linux?

However build process still fails with the following exception:

/opt/JetBrains/apps/CLion/ch-0/181.4668.70/bin/cmake/bin/cmake --build /home/user/Documents/Projects/GdvProject/cmake-build-debug --target testas -- -j 2
CMake Error at CMakeLists.txt:9 (target_link_libraries):
  Cannot specify link libraries for target "GdvProject" which is not built by
  this project.


-- Configuring incomplete, errors occurred!
See also "/home/user/Documents/Projects/GdvProject/cmake-build-debug/CMakeFiles/CMakeOutput.log".
make: *** [Makefile:176: cmake_check_build_system] Error 1

My CMakeLists file looks like this:

cmake_minimum_required(VERSION 2.8)

project(GdvProject)
add_executable(testas main.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS}  ${GLUT_INCLUDE_DIRS} )

target_link_libraries(GdvProject ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})

How can I fix this issue?

Upvotes: 0

Views: 338

Answers (1)

Botje
Botje

Reputation: 30807

target_link_libraries wants a target name. Targets are specified by (among others) add_executable, add_library and add_custom_target.

In other words, target_link_libraries(testas ...) should work. While you're at it, you should consider switching your include_directories(...) to target_include_directories(testas ...) as well.

Upvotes: 1

Related Questions