簡體   English   中英

如何將 GLFW 庫鏈接到 CLION (Windows)?

[英]How to link GLFW library to CLION (Windows)?

首先,我從他們的網站下載了適用於 Windows 的 GLFW 32 位二進制文​​件。 以下是本次下載的內容:

target_link_libraries(myapp glfw)

然后,我將“include”和“lib-vc2019”文件復制到我的 Clion 項目文件夾“OpenGL”下名為“Dependencies”的文件夾中:

在此處輸入圖片說明

按照https://www.glfw.org/docs/3.3/build_guide.html#build_link_cmake_package 中的“使用 CMake 並安裝 GLFW 二進制文件”中的說明進行操作

在我的 CMakeLists.txt 文件中,我有以下內容:

cmake_minimum_required(VERSION 3.19)
project(OpenGL)

set(CMAKE_CXX_STANDARD 20)

add_executable(OpenGL Main.cpp)

include_directories(Dependencies)

find_package(glfw3 3.3 REQUIRED)
target_link_libraries(OpenGL glfw)

當我嘗試構建時,出現以下錯誤:

CMake Error at CMakeLists.txt:10 (find_package):
  By not providing "Findglfw3.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "glfw3", but
  CMake did not find one.

  Could not find a package configuration file provided by "glfw3" (requested
  version 3.3) with any of the following names:

    glfw3Config.cmake
    glfw3-config.cmake

  Add the installation prefix of "glfw3" to CMAKE_PREFIX_PATH or set
  "glfw3_DIR" to a directory containing one of the above files.  If "glfw3"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!
See also "C:/Users/moehe/Desktop/CS/CPP/OpenGL/cmake-build-debug/CMakeFiles/CMakeOutput.log".
mingw32-make.exe: *** [Makefile:194: cmake_check_build_system] Error 1

花了很多時間在這上面,非常困惑。 如果有人可以提供逐步指導來完成這項工作,將不勝感激。

您誤解了“已安裝”部分:那些會生成 glfw3Config.cmake 文件,告訴 CMake 庫和頭文件所在的位置。 find_package將查找並加載該文件。

將 CMake 文件的最后兩行替換為以下內容。 這將使用預定義的庫和頭文件設置 CMake 目標:

add_library(glfw STATIC IMPORTED)
set_target_properties(glfw PROPERTIES
  IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/Dependencies/lib-vc2019/glfw3.lib"
  INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(OpenGL glfw)

請參閱非凡的使用 CMake 的時間來很好地介紹現代 CMake。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM