【问题标题】:How to add OpenGL library in CLion?如何在 CLion 中添加 OpenGL 库?
【发布时间】:2017-04-04 07:31:35
【问题描述】:

我有一个名为 GL 的文件夹,其中包含以下文件:

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

我在 Visual Studio 中处理过这些文件,但我是 CLion 的新手,这就是为什么不知道链接目录如何通过 CMake 工作的原因。如何使用 CLion 中的库?

【问题讨论】:

  • 这只是一般的“我如何在 CLion 中链接库”问题吗?
  • 与此非常相似。我已经尝试过intellij-support.jetbrains.com/hc/en-us/articles/… 中的说明,但它对我不起作用。通常该库带有许多文件,但我只想使用这些文件,这就是我制作单独目录并尝试添加 clion 的原因。我不明白我错过了什么

标签: opengl cmake clion


【解决方案1】:

在 Google 上进行了大量搜索后,我已使其在 Windows 10 和 Linux (Ubuntu 16.04) 中运行。显然,它毕竟不是那么容易找到。所以,我现在和这里要结束这个问题。

在这里,我将向您展示如何配置 CMakeLists.txt 文件来编译 OpenGL 程序,这是这里的主要挑战。我假设您可以编写基本的 OpenGL 程序并且您已经编写了一个名为 'demoMain.cpp'。

对于 Windows

我假设您可以在 Windows 上设置 OpenGL。如果你不能,youtube 和 StackOverflow 上有很多教程。之后,继续。

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)

适用于 Linux (Ubuntu 16.04)

它也应该适用于其他 Ubuntu 版本。 Linux 使 OpenGL 的使用比 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

#################################################

我假设您可以在 Ubuntu 上安装 OpenGL。如果你遇到这个问题,

点击此链接 - http://www.codebind.com/linux-tutorials/install-opengl-ubuntu-linux/ 。 如果这不起作用,请按照此操作 - https://gist.github.com/shamiul94/a632f7ab94cf389e08efd7174335df1c

【讨论】:

    【解决方案2】:

    我已通过在 CMake 文件中添加以下行来解决我的问题

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

    【讨论】:

      猜你喜欢
      • 2020-12-27
      • 1970-01-01
      • 2020-06-08
      • 2020-09-21
      • 2017-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多