0

我一直在尝试使用 glfw3 和 GLAD 为 OpenGL 建立构建环境。我目前正在使用带有 X 服务器的 WSL2 Ubuntu 进行编译和生成文件。

但是,当我运行我的 make 时,我收到以下错误:

src/glad.c:25:10:致命错误:glad/glad.h:没有这样的文件或目录 25 | #include <高兴/高兴.h>

这对我来说很奇怪,因为 makefile 似乎能够编译 main.cpp 文件并创建一个 main.o,尽管还包括“glad/glad.h”

文件结构:

-HelloTriangle
--include
---glad
----glad.h
---KHR
----khrplatform.h
--src
---glad.c
---main.cpp
--makefile

这是我的制作文件:

BASE_OBJS = main.o glad.o

SRC_PATH = src

OBJS = $(addprefix $(SRC_PATH)/, $(BASE_OBJS))
CXX = g++
CXXFLAGS = -g -Iinclude
LDFLAGS =
LDLIBS = -lglfw -lGL -lX11 -lpthread -lXrandr -lXi -ldl

HelloTriangle: $(OBJS)
    $(CXX) -o $@ $(LDFLAGS) $^ $(LDLIBS)    

clean:
    rm $(OBJS)

这是我的 main.cpp:

#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>

#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600

/*
Function to handle window resizing
*/
void framebuffer_size_callback(GLFWwindow* window, int width, int height);

int main() {
    /* 
    Initialize GLFW
    Sets version to Core profile 3.3
     */
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    /* 
    Initialize a window context for OpenGL
    Defines the windows width, height, and title
     */
    GLFWwindow* window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Hello Triangle", NULL, NULL);
    if(window == NULL) {
        std::cout << "Failed to create GLFW window" <<std::endl;
        glfwTerminate();
        return -1;
    }

    /* 
    Initialize GLAD
    Handles OS-specific function pointers
    */
    if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
        std::cout << "Failed to initialize GLAD" << std::endl;
        return -1;
    }

    /*
    Handle window resizing
    */
    glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

    /*
    Render loop
    */
    while(!glfwWindowShouldClose(window)) {
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

void framebuffer_size_callback(GLFWwindow* window, int width, int height) { glViewport(0, 0, width, height); }
4

1 回答 1

4

您似乎设置了 CXXFLAGS(用于 C++ 编译器),但您的glad.c 是使用 C 编译器(检查 CFLAGS)编译的

于 2021-05-25T22:53:25.023 回答