LNK1104:无法打开文件“glfw.lib”

问题描述 投票:0回答:1

build] LINK : fatal error LNK1104: cannot open file 'glfw.lib' [E:\Z_Dev\OpenGl\build\hello_window.vcxproj]

请有人帮我将其添加到我的项目中,我不知道如何通过 CMAKE 添加它,我已经尝试了很多小时来弄清楚我自己

我已附上我的项目文件的图像和 LIB 的文件地址

这是我的 CMake 文件:

`cmake_minimum_required(VERSION 3.5)
project(hello_window VERSION 1.0.0)

add_executable(hello_window src/config.h src/main.cpp)

target_include_directories(hello_window PRIVATE dependencies)

target_link_libraries(hello_window glfw)

target_link_libraries(hello_window lib)
`

这是我的main.cpp:

`#include "config.h"

int main() {
    
    GLFWwindow* window;

    if(!glfwInit()){
        std::cout << "GLFW couldn't start" << std::endl;
        return -1;
    }

    window = glfwCreateWindow(640, 400, "My_Window", NULL, NULL);
    
    while(!glfwWindowShouldClose(window))
    {
       glfwPollEvents(); 
    }

    glfwTerminate();
    return 0;
}`

我的config.h文件:

#pragma once  #include <iostream> #include <GLFW/glfw3.h> 

在此输入图片描述

在此输入图片描述

我尝试将 LIB 文件夹添加到我的项目中,然后使用

target_link_libraries(hello_window lib)

但是我仍然收到错误,我不知道如何添加它

c++ visual-studio visual-studio-code linker-errors glfw
1个回答
0
投票

尝试在项目定义后包含

find_package(glfw3 REQUIRED)
。另外,要添加库文件夹,您应该使用
target_link_directories(hello_window LIB)

© www.soinside.com 2019 - 2024. All rights reserved.