使用 Derelict 和 SDL 进行 D 编程
您好,我最近通过查看 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要链接 Derelict2 的库。
在导入下方添加:
例如:
如果您使用的是 Windows,则这些库文件将为
.lib
来将文件添加到构建命令中:
或者,您可以通过添加这些标志 事情,你应该只需要引用SDL库。
You need to link with Derelict2's libraries.
Below the imports, add:
For example:
If you are on Windows then those library files will be
.lib
sAlternatively, you can add the files to your build command by adding these flags:
By the looks of things, you should only need to reference the SDL library.
只需使用 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.