使用 Derelict 和 SDL 进行 D 编程

发布于 2024-12-17 16:08:51 字数 1317 浏览 1 评论 0原文

您好,我最近通过查看 Derelict2 分支此处下载了 Derelict2 我尝试使用 SDL 编写一个小程序:

import derelict.sdl.sdl;

int main()
{
  bool run = true;
  SDL_Init(SDL_INIT_VIDEO);
  SDL_SetVideoMode(400, 300, 32, SDL_HWSURFACE | SDL_RESIZABLE | SDL_DOUBLEBUF);
  SDL_Event event;
  while(run)
  {
    SDL_WaitEvent(&event);
    switch(event.type)
    {
      case SDL_QUIT:
      run = false;
    } 
  }
  return 0;
}

我使用此命令行进行编译:

ldc2 -I=/usr/include/d/Derectlict2/DerelictSDL -I=/usr/include/d/Derectlict2/DerelictUtil -of=../bin/test -release -run main.d

但存在此错误:

../bin/test.o: In function `_Dmain':
main:(.text+0x40): undefined reference to `_D8derelict3sdl8sdlfuncs8SDL_InitPUkZi'
main:(.text+0x69): undefined reference to `_D8derelict3sdl8sdlfuncs16SDL_SetVideoModePUiiikZPS8derelict3sdl8sdltypes11SDL_Surface'
main:(.text+0xa2): undefined reference to `_D8derelict3sdl8sdlfuncs13SDL_WaitEventPUPS8derelict3sdl8sdltypes9SDL_EventZi'
../bin/test.o:(.rodata+0x2c): undefined reference to `_D8derelict3sdl3sdl8__ModuleZ'
collect2: ld returned 1 exit status
Error: linking failed:
status: 1

我是 D 和一般编程的真正初学者,而且我不明白目标文件是什么。

所以如果有人理解我做错了什么请告诉我

Hello I recently download Derelict2 by checking out the Derelict2 branch here
and I try a little program with SDL :

import derelict.sdl.sdl;

int main()
{
  bool run = true;
  SDL_Init(SDL_INIT_VIDEO);
  SDL_SetVideoMode(400, 300, 32, SDL_HWSURFACE | SDL_RESIZABLE | SDL_DOUBLEBUF);
  SDL_Event event;
  while(run)
  {
    SDL_WaitEvent(&event);
    switch(event.type)
    {
      case SDL_QUIT:
      run = false;
    } 
  }
  return 0;
}

I compile with this command line :

ldc2 -I=/usr/include/d/Derectlict2/DerelictSDL -I=/usr/include/d/Derectlict2/DerelictUtil -of=../bin/test -release -run main.d

but there is this error :

../bin/test.o: In function `_Dmain':
main:(.text+0x40): undefined reference to `_D8derelict3sdl8sdlfuncs8SDL_InitPUkZi'
main:(.text+0x69): undefined reference to `_D8derelict3sdl8sdlfuncs16SDL_SetVideoModePUiiikZPS8derelict3sdl8sdltypes11SDL_Surface'
main:(.text+0xa2): undefined reference to `_D8derelict3sdl8sdlfuncs13SDL_WaitEventPUPS8derelict3sdl8sdltypes9SDL_EventZi'
../bin/test.o:(.rodata+0x2c): undefined reference to `_D8derelict3sdl3sdl8__ModuleZ'
collect2: ld returned 1 exit status
Error: linking failed:
status: 1

I'm a really beginner in D and in programming in general, and I don't understand what's are the object file.

So if anyone understand what I did wrong please tell me

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

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

发布评论

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

评论(2

梦里人 2024-12-24 16:08:51

您需要链接 Derelict2 的库。

在导入下方添加:

pragma(lib, "relevant-libraries");

例如:

pragma(lib, "/usr/include/d/Derelict2/lib/libDerelictGL.a");
pragma(lib, "/usr/include/d/Derelict2/lib/libDerelictGLU.a");
pragma(lib, "/usr/include/d/Derelict2/lib/libDerelictSDL.a");
pragma(lib, "/usr/include/d/Derelict2/lib/libDerelictUtil.a");

如果您使用的是 Windows,则这些库文件将为 .lib

来将文件添加到构建命令中:

-L/usr/inlcude/d/Derelict2/lib/libDerelictSDL.a -L/usr/ ... etc.

或者,您可以通过添加这些标志 事情,你应该只需要引用SDL库。

You need to link with Derelict2's libraries.

Below the imports, add:

pragma(lib, "relevant-libraries");

For example:

pragma(lib, "/usr/include/d/Derelict2/lib/libDerelictGL.a");
pragma(lib, "/usr/include/d/Derelict2/lib/libDerelictGLU.a");
pragma(lib, "/usr/include/d/Derelict2/lib/libDerelictSDL.a");
pragma(lib, "/usr/include/d/Derelict2/lib/libDerelictUtil.a");

If you are on Windows then those library files will be .libs

Alternatively, you can add the files to your build command by adding these flags:

-L/usr/inlcude/d/Derelict2/lib/libDerelictSDL.a -L/usr/ ... etc.

By the looks of things, you should only need to reference the SDL library.

不奢求什么 2024-12-24 16:08:51

只需使用 rdmd 即可,如第二行。

但奇怪的是,它抱怨 _D8derelict3sdl8sdlfuncs8SDL_InitPUkZi
看起来缺少 extern(C)。

Just use rdmd like that, second line.

Strange thing is though, that it complains about _D8derelict3sdl8sdlfuncs8SDL_InitPUkZi.
Looks like an extern(C) is missing.

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