(CMake构建)致命错误LNK1181:无法打开输入文件'glew.lib'

时间:2019-01-18 22:14:07

标签: c++ cmake

我正在使用游戏引擎,最近尝试创建CMakeLists.txt来构建项目。我设法创建了一个配置并生成的cmakelist,但是当我尝试在Visual Studio中运行generate .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)```

1 个答案:

答案 0 :(得分:2)

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

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

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