c - 在 nim 中链接到 vulkan

标签 c visual-studio-2015 glfw vulkan nim-lang

我无法弄清楚如何将更复杂的库链接到 nim 程序。给定以下包含目录(分隔到不同的行):

C:\Users\[user]\Documents\visual studio 2015\Libraries\glfw-3.2.bin.WIN32\lib-vc2015;
C:\VulkanSDK\1.0.13.0\Source\lib32;
C:\Users\[user]\Documents\Visual Studio 2015\Libraries\glfw-3.2.bin.WIN32\include;
C:\VulkanSDK\1.0.13.0\Include\ 

还有这个额外的库搜索目录(与上面的第一个相同):

C:\Users\[user]\Documents\visual studio 2015\Libraries\glfw-3.2.bin.WIN32\lib-vc2015;

使用这段代码:

#define GLFW_INCLUDE_VULKAN

#include <GLFW/glfw3.h>
//#include <stdio.h>

GLFWwindow* init() {
    glfwInit();

    glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
    GLFWwindow* window = glfwCreateWindow(800, 600, "Vulkan window", NULL, NULL);

    int extensionCount = 0;
    vkEnumerateInstanceExtensionProperties(NULL, &extensionCount, NULL);

    //printf("%d extensions supported\n", extensionCount);

    return window;
}

void close(GLFWwindow* window) {
    glfwDestroyWindow(window);
    glfwTerminate();
}

int shouldClose(GLFWwindow* window) {
    return glfwWindowShouldClose(window);
}

void pollEvents() {
    glfwPollEvents();
}

int main() {
    GLFWwindow* window = init();

    while (!shouldClose(window)) {
        pollEvents();
    }

    close(window);
    return 0;
}

在从顶部正确设置属性的 Visual Studio 2015 中,我可以运行它,它会打开一个空白窗口。

要使等效代码在纯 Nim 中运行,需要做什么?我想过如何通过使用 gcc 而不是 VS15 进行编译来做到这一点,因为可视化 C 编译器似乎限制太多。

我已经编写了以下 nim 代码来尝试从 VS15 链接一个没有主函数的 dll:

{.link: "VulkanTest.dll".}

proc pollEvents() {.importc, dynlib: "VulkanTest.dll".}
proc init(): pointer {.importc, dynlib: "VulkanTest.dll".}
proc close(window: pointer) {.importc, dynlib: "VulkanTest.dll".}
proc shouldClose(window: pointer): cint {.importc, dynlib: "VulkanTest.dll".}

var window = init()

while shouldClose(window) != 0:
    pollEvents()

close(window)

但它只是说它无法打开文件(dll)。

是否需要在命令行中输入一些内容才能使其正常工作? e.i. -l-p (我能想到的每次使用 -p 都不起作用,即使在反转斜杠并将 url 后面的 ; 分隔符更改为 unix 样式 : 之后也是如此)

#define GLFW_INCLUDE_VULKAN 等价于什么在 #include <GLFW/glfw3.h> 之前对于 nim 编译器?

最佳答案

but it simply says it cannot open the file (the dll).

这意味着文件 VulkanTest.dll 在您用作后端 (VC) 的编译器的搜索路径中不可用。您可以尝试使用 --passL:"/LIBPATH:path" 添加 dll 所在的路径,其中 path 是包含 dll 的文件夹的路径。

What is the equivilant of putting the #define GLFW_INCLUDE_VULKAN before the #include for the nim compiler?

这是不必要的,因为 GLFW_INCLUDE_VULKAN 所做的只是包含 Vulkan header 。但是你需要在 Nim 端声明你想要调用的过程。有一个 GLFW3 wrapper和一个 Vulkan wrapper它会为您做到这一点,但我相信 Vulkan 包装器是相当实验性的。

关于c - 在 nim 中链接到 vulkan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40187637/

相关文章:

c++ - GLFW 窗口 glfwSwapBuffers() 真的很慢吗?

python - 如何从Python扩展模块的C代码调用内置函数(或方法)?

c - 如何向使用 Eclipse Galileo C 和 MinGW 构建的应用程序添加图标?

c - 如何在c中分割字符串中的单词?

c - 使 `gcc' 需要 : *** No rule to make target `all' , 。停止

c - 如何修复Glad.c中对符号 'dlclose@@GLIBC_2.2.5'的 undefined reference

c++ - 将程序链接到静态库,将自身链接到另一个库

vb.net - VS2015升级到最新的Visual Basic

visual-studio - VS 2015 社区 - 由于构建错误,发布失败。

c++ - 做一个循环 "slow down"