简体   繁体   中英

How to link GLFW library to CLION (Windows)?

First I downloaded the GLFW 32 bit binaries for Windows from their website. Below are the contents of this download:

target_link_libraries(myapp glfw)

I then copied the "include" and "lib-vc2019" files into a folder called "Dependencies" under my Clion project folder "OpenGL":

在此处输入图片说明

Following the instructions from "With CMake and installed GLFW binaries" from https://www.glfw.org/docs/3.3/build_guide.html#build_link_cmake_package

In my CMakeLists.txt file I have the following:

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)

When I try to build, I get the following errors:

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

Have spent a lot of time on this and very confused. If someone could provide a step by step guidance to make this work, would greatly appreciate it.

You misunderstood the "installed" part: those generate a glfw3Config.cmake file that tells CMake where the library and headers live. find_package will find and load that file.

Replace the last two lines of your CMake file with the following. This sets up a CMake target with the predefined library and header files:

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)

See the phenomenal It's time to do CMake right for a good introduction to modern CMake.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM