CLion编译glut linux(CLion compile glut linux)

编程入门 行业动态 更新时间:2024-10-25 09:23:49
CLion编译glut linux(CLion compile glut linux)

我正在尝试在使用freeglut的linux上编译一个C ++项目。 我无法构建项目,因为CMake文件中的库没有正确链接。 我研究并尝试应用在类似的答案中提到的内容: 如何在Linux中使用CMake和Kdevelop编译GLUT + OpenGL项目?

但是,构建过程仍然失败,但有以下例外:

/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

我的CMakeLists文件如下所示:

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})

我该如何解决这个问题?

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?

最满意答案

target_link_libraries一个目标名称。 目标由(除其他之外) add_executable , add_library和add_custom_target 。

换句话说, target_link_libraries(testas ...)应该可以工作。 在你处理它时,你应该考虑将include_directories(...)切换到target_include_directories(testas ...) 。

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.

更多推荐

本文发布于:2023-08-03 15:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1395141.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:glut   CLion   compile   linux

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!