为什么在构建我的 C++ 代码时 cmake return 出错?
Why does cmake return an error when i build my c++ code?
我想开始学习 OpenGL,所以我学习了一些 C++,安装了 CLion (JetBrains IDE),并尝试使一切正常。我在 Ubuntu 20.04 上工作。我检查了是否安装了 freeglut 和 OpenGL,我不知道还能做什么。
这是 CMakeLists.txt
文件:
cmake_minimum_required(VERSION 3.16)
project(OpenGlmessing)
set(CMAKE_CXX_STANDARD 17)
add_executable(OpenGlmessing main.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories(${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS})
target_link_libraries(${OpenGlmessing} ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
我得到的错误是:
CMake Error at CMakeLists.txt:13 (target_link_libraries):
Cannot specify link libraries for target
"/usr/lib/x86_64-linux-gnu/libOpenGL.so" which is not built by this
project.
您可能需要删除 target_link_libraries
中的“$”
target_link_libraries(OpenGlmessing ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
我想开始学习 OpenGL,所以我学习了一些 C++,安装了 CLion (JetBrains IDE),并尝试使一切正常。我在 Ubuntu 20.04 上工作。我检查了是否安装了 freeglut 和 OpenGL,我不知道还能做什么。
这是 CMakeLists.txt
文件:
cmake_minimum_required(VERSION 3.16)
project(OpenGlmessing)
set(CMAKE_CXX_STANDARD 17)
add_executable(OpenGlmessing main.cpp)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories(${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS})
target_link_libraries(${OpenGlmessing} ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
我得到的错误是:
CMake Error at CMakeLists.txt:13 (target_link_libraries):
Cannot specify link libraries for target
"/usr/lib/x86_64-linux-gnu/libOpenGL.so" which is not built by this
project.
您可能需要删除 target_link_libraries
中的“$”target_link_libraries(OpenGlmessing ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})