(CMake 内部版本)致命错误LNK1181:无法打开输入文件'glew.lib'

(CMake build) fatal error LNK1181: cannot open input file 'glew.lib'

本文关键字:输入 文件 lib glew 版本 内部 CMake 致命错误 LNK1181      更新时间:2023-10-16

我正在开发一个游戏引擎,最近尝试创建一个CMakeLists.txt来构建项目。我设法创建了一个配置和生成的cmakelist,但是当我尝试在视觉工作室中运行生成.sln时,我收到以下错误:

fatal error LNK1181: cannot open input file 'glew.lib'

我的游戏引擎使用外部库 glew 和 glfw。这是我的 cmakelist 文件:

cmake_minimum_required(VERSION 3.7)
project(GameEngine)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/Engine/source)
set(ENGINE_SOURCES ${SOURCE_DIR}/core/Engine.cpp
           ${SOURCE_DIR}/graphics/gl_types/IndexBuffer.cpp
           ${SOURCE_DIR}/graphics/gl_types/VertexArray.cpp
           ${SOURCE_DIR}/graphics/gl_types/VertexBuffer.cpp
           ${SOURCE_DIR}/graphics/renderer/Camera.cpp
           ${SOURCE_DIR}/graphics/renderer/Shader.cpp
           ${SOURCE_DIR}/graphics/renderer/Texture.cpp
           ${SOURCE_DIR}/graphics/renderer/Window.cpp
           ${SOURCE_DIR}/vendor/stb_image/stb_image.cpp)
add_library(engine STATIC ${ENGINE_SOURCES})
target_include_directories(engine PUBLIC ${SOURCE_DIR})

set(glfw3_DIR ${CMAKE_SOURCE_DIR}/Dependencies/GLFW/lib/cmake/glfw3)
find_package(glfw3 REQUIRED)
set(glew_DIR ${CMAKE_SOURCE_DIR}/Dependencies/GLEW)
find_library(glew glew32s "${glew_DIR}/lib/Release/Win32")
include_directories(${GLFW_INCLUDE_DIRS})
include_directories(${glew_DIR}/include)
target_link_libraries(
        engine
        glfw
        glew
)
set(GAME_DIR ${CMAKE_SOURCE_DIR}/Game/source)
set(GAME_SOURCES ${GAME_DIR}/main.cpp)
add_executable(engine_game ${GAME_SOURCES})
target_link_libraries(engine_game engine)```

您正在使用设置变量的find_library。您必须这样使用它们:

target_link_libraries(
        engine
        ${glfw_LIBRARIES}
        ${glew}
)

我假设glfw_LIBRARIESfind_package(glfw)设置的变量。