D 和 SDL - 函数未定义

发布于 2024-10-18 22:32:13 字数 650 浏览 6 评论 0原文

我有一个非常简单的 D 程序 (pk.d):

import std.stdio;
import SDL;

int main(string[] args) {
    writefln("Hello world");
    if (SDL_Init( SDL_INIT_VIDEO ) < 0) {
        writefln("Unable to init SDL");
        return 1;
    }

    return 0;
}

我有一个非常简单的 make 脚本(我使用的是 Windows,但 Windows D 编译器附带了 bash 解释器):

DMD=dmd
DFLAGS=-I./lib/SDL 

$(DMD) pk $(DFLAGS)
pk

但是当我构建它,得到错误 42:符号未定义 _SDL_Init

它成功导入 SDL,并且发现 SDL_INIT_VIDEO 很好。我继续查看 SDL.d,发现 SDL_Init 有一个定义:int SDL_Init(Uint32 flags);。我无法弄清楚这一点。这是我用 D 导入的第一个非 STL 库,所以希望我的错误是明显的,有人能看到吗?

I've got this very simple D program (pk.d):

import std.stdio;
import SDL;

int main(string[] args) {
    writefln("Hello world");
    if (SDL_Init( SDL_INIT_VIDEO ) < 0) {
        writefln("Unable to init SDL");
        return 1;
    }

    return 0;
}

I've got a very straightforward make script (I'm on Windows here, but the Windows D compiler comes packaged with a bash interpreter):

DMD=dmd
DFLAGS=-I./lib/SDL 

$(DMD) pk $(DFLAGS)
pk

But when I build it, I get Error 42: Symbol Undefined _SDL_Init

It managed to import SDL alright, and it finds SDL_INIT_VIDEO just fine. I went ahead and checked in SDL.d and found that there was a definition for SDL_Init: int SDL_Init(Uint32 flags);. I can't figure this out. This is the first non-STL library that I've imported with D, so hopefully my mistake is obvious, can anyone see it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情深已缘浅 2024-10-25 22:32:13

您还必须链接到 SDL 库。如果您有正确格式的文件,只需将其与源文件一起传递给编译器即可。或者,您可以将诸如 pragma(lib, "SDL.lib") 之类的内容添加到您的程序中。

You also have to link with the SDL library. If you have one in the right format, simply pass it to the compiler along with your source files. Alternatively, you can add something like pragma(lib, "SDL.lib") to your program.

青萝楚歌 2024-10-25 22:32:13

首先,您还需要 SDL 库的 D 绑定。

import std.stdio;
import sdl;

int main(string[] args)
{
    SDL_Surface * screen;

    SDL_Init(SDL_INIT_EVERYTHING);
    screen = SDL_SetVideoMode(800, 600, 24, SDL_SWSURFACE);

    SDL_FillRect(screen, &screen.clip_rect, SDL_MapRGB(screen.format, 
                                                       0xFF, 0x00, 0x00));
    SDL_Flip(screen);

    SDL_Delay(6000);
    return 0;
}

这是我的示例测试程序。首先我下载了​​ VC6 的 SDL 开发库

您需要将库文件转换为 OMF 格式。我更喜欢 coff2omf 工具,它与 Borland C++ Compiler 一起提供,因为它是免费的。 DigitalMars 有一个同名的工具,但它不是免费的。这对我来说没有意义。

coff2omf.exe SDL.lib SDL2.lib

然后我像这样编译和链接:

dmd -c test.d sdl.d

link test.obj sdl。 obj SDL2.lib

它对我有用。

First of all you need also D bindings for SDL library.

import std.stdio;
import sdl;

int main(string[] args)
{
    SDL_Surface * screen;

    SDL_Init(SDL_INIT_EVERYTHING);
    screen = SDL_SetVideoMode(800, 600, 24, SDL_SWSURFACE);

    SDL_FillRect(screen, &screen.clip_rect, SDL_MapRGB(screen.format, 
                                                       0xFF, 0x00, 0x00));
    SDL_Flip(screen);

    SDL_Delay(6000);
    return 0;
}

This is my sample test program. First of all I downloaded SDL development libraries for VC6

Than you need to convert library files to OMF format. I preferred coff2omf tool which ships with Borland C++ Compiler because it is free. DigitalMars has a tool with same name but it isn't free. Which doesn't make sense to me.

coff2omf.exe SDL.lib SDL2.lib

And than I compiled and linked like that:

dmd -c test.d sdl.d

link test.obj sdl.obj SDL2.lib

It works for me.

最好是你 2024-10-25 22:32:13

另外,如果您需要 SDL 库的 D 绑定,您可以从此处下载。文件名为sdl.d,但尚未完成。

Also if you need D bindings for SDL library you may download from here. File name is sdl.d but not complete yet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文