为 GFLW 编写 C++/CLI 包装器

Writing a C++/CLI wrapper for GFLW

本文关键字:CLI 包装 C++ GFLW 编写      更新时间:2023-10-16

我正在尝试为 GLFW 编写一个 C++/CLI 包装器。我创建了一个名为 GLFWWrapper 的 CLR 类库项目,并将glfw3.lib添加到其他依赖项,并将头文件文件夹添加到其他包含目录中。

到目前为止,我的GLFWWrapper.h看起来像这样:

// GLFWWrapper.h
#pragma once
#include <GLFWglfw3.h>
using namespace System;
namespace GLFWWrapper {
    public ref class Window
    {
    public:
        Window(int width, int height, char * title);
    private:
        GLFWwindow * m_ptr;
    };
}

我的GLFWWrapper.cpp看起来像这样:

// This is the main DLL file.
#include "stdafx.h"
#include "GLFWWrapper.h"
namespace GLFWWrapper {
    Window::Window(int width, int height, char * title) {
        if (glfwInit() != GL_TRUE) {
        }
        else {
            m_ptr = glfwCreateWindow(width, height, title, nullptr, nullptr);
        }
    }
}

现在,当我尝试编译它时,我收到以下警告:

GLFWWrapper.obj :警告LNK4248:未解析的 'GLFWwindow' 的 typeref 令牌 (01000008);图像可能无法运行
GLFWWrapper.obj : 警告LNK4248:未解析的 typeref 令牌 (0100000B) for 'GLFWmonitor';映像可能无法运行

它们在我的上下文中意味着什么,这会有问题吗?

添加:

struct GLFWwindow {};
struct GLFWmonitor {};

之前:

#include <GLFW/glfw3.h>

这至少会消除警告。我没有设置验证它是否会正确执行,但我认为这对您和需要做您正在做的事情的任何其他人来说都很容易做到。