为 GFLW 编写 C++/CLI 包装器
Writing a C++/CLI wrapper for GFLW
我正在尝试为 GLFW 编写 C++/CLI 包装器。我创建了一个名为 GLFWWrapper 的 CLR Class 库项目,并将 glfw3.lib
添加到附加依赖项,并将头文件文件夹添加到附加包含目录。
我的 GLFWWrapper.h 目前看起来是这样的:
// GLFWWrapper.h
#pragma once
#include <GLFW\glfw3.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 : warning LNK4248: unresolved typeref token (01000008) for 'GLFWwindow'; image may not run
GLFWWrapper.obj : warning LNK4248: unresolved typeref token (0100000B) for 'GLFWmonitor'; image may not run
它们在我的上下文中是什么意思,这会不会有问题?
添加:
struct GLFWwindow {};
struct GLFWmonitor {};
之前:
#include <GLFW/glfw3.h>
这至少会消除警告。我没有设置来验证它是否会正确执行,但我认为这对你和任何其他需要做你正在做的事情的人来说很容易做到。
我正在尝试为 GLFW 编写 C++/CLI 包装器。我创建了一个名为 GLFWWrapper 的 CLR Class 库项目,并将 glfw3.lib
添加到附加依赖项,并将头文件文件夹添加到附加包含目录。
我的 GLFWWrapper.h 目前看起来是这样的:
// GLFWWrapper.h
#pragma once
#include <GLFW\glfw3.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 : warning LNK4248: unresolved typeref token (01000008) for 'GLFWwindow'; image may not run
GLFWWrapper.obj : warning LNK4248: unresolved typeref token (0100000B) for 'GLFWmonitor'; image may not run
它们在我的上下文中是什么意思,这会不会有问题?
添加:
struct GLFWwindow {};
struct GLFWmonitor {};
之前:
#include <GLFW/glfw3.h>
这至少会消除警告。我没有设置来验证它是否会正确执行,但我认为这对你和任何其他需要做你正在做的事情的人来说很容易做到。