www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - xfbuild, optlink and pragma(lib)

reply Mafi <mafi example.org> writes:
Hi,
I wanted to create an simple wrapper around SDL. After my simple first 
steps, I wanted to create a simple application using my wrapper. That's it:
///////
module test;

import std.stdio;
import mysdl.system;

//pragma(lib,r"Path\to\SDL\lib\libSDLmain.a");
pragma(lib,r"Path\to\SDL\lib\libSDL.dll.a");


void main() {
   initAll(); //Init all SDL-subsystems
}
////////
I tried to compile it using
xfbuild test.d +full +xstd +xcore -debug -I.. +v +o=test
(-I.. -> there is mysdl)
That doesn't work! It doesn't create any executable but there's no 
error. Because xfbuild -v doesn't show the linker-command either I tried 
to reproduce it myself. It seems that optlink is the problem because it 
does nothing but shows no errormessages.

When I comment out the pragma(lib) optlink fails (correctly) and xfbuild 
crashes (:-(). Then I call optlink myself with libsdl.dll.a and it 
creates a corrupt exe without errormessages.

Please help me. It seems that there are bugs over bugs. I don't konw 
what to do.

I use Windows 7, dmd (2.047), xfbuild with cmd/powershell.

PS: I know there's Derelict but wanted to create this myself as a task 
for learning D.
Jul 30 2010
next sibling parent Mafi <mafi example.org> writes:
Ok,
OPTLINK is the problem. Without linking SDL, it complains about missing 
symbol (good) and creates a corrupt executable (so-so). With linking SDL 
in any way (explicitly or with pragma(lib)) it shows no errormessage 
(really bad) and does not create any executable (bad).
Should I fill a bug report or am I doing something wrong?
Aug 01 2010
prev sibling parent reply Mike Parker <aldacron gmail.com> writes:
Mafi wrote:

 
 When I comment out the pragma(lib) optlink fails (correctly) and xfbuild 
 crashes (:-(). Then I call optlink myself with libsdl.dll.a and it 
 creates a corrupt exe without errormessages.
 
 Please help me. It seems that there are bugs over bugs. I don't konw 
 what to do.
 
 I use Windows 7, dmd (2.047), xfbuild with cmd/powershell.

libSDL.dll.a is a MingW- or Cygwin-compiled link library. That's not going to work on Windows with DMD and may very likely be the source of your problem. If you want to link with a DLL link lib, then you need to get the tool coff2omf[1] (part of the Extended Utilities Package[2]) run it on SDL.lib (I suppose it might work on SDL.dll.a), and link with the resulting converted file. Either that or compile SDL with DMC. Alternatively, you could modify your binding to load SDL dynamically like Derelict does. Then you don't need to fool around with any link libs. But, you do need a fair amount of implementation code to load the function symbols from the DLL. [1] http://www.digitalmars.com/ctg/coff2omf.html [2] http://www.digitalmars.com/download/freecompiler.html
Aug 01 2010
next sibling parent reply Mafi <mafi example.org> writes:
 libSDL.dll.a is a MingW- or Cygwin-compiled link library. That's not
 going to work on Windows with DMD and may very likely be the source of
 your problem. If you want to link with a DLL link lib, then you need to
 get the tool coff2omf[1] (part of the Extended Utilities Package[2]) run
 it on SDL.lib (I suppose it might work on SDL.dll.a), and link with the
 resulting converted file. Either that or compile SDL with DMC.

 Alternatively, you could modify your binding to load SDL dynamically
 like Derelict does. Then you don't need to fool around with any link
 libs. But, you do need a fair amount of implementation code to load the
 function symbols from the DLL.

 [1] http://www.digitalmars.com/ctg/coff2omf.html
 [2] http://www.digitalmars.com/download/freecompiler.html

The tool sounds cool but it seems that I have to buy it, so that's no option for me. So I tried to compile SDL myself. I have to say I'm to stupid for it. I tried to do the same thing as the makefile in powershell. After I hacked together some solution that worked dmc complained about missing Gl.h. It isn't there. So I added some MinGW to the include-path and then I get a bunch of errors in SDL without linenumbers. And anyways I am trying to compile it without MinGW, aren't I. Please, help me!
Aug 01 2010
next sibling parent div0 <div0 sourceforge.net> writes:
On 01/08/2010 16:22, Mafi wrote:
 libSDL.dll.a is a MingW- or Cygwin-compiled link library. That's not
 going to work on Windows with DMD and may very likely be the source of
 your problem. If you want to link with a DLL link lib, then you need to
 get the tool coff2omf[1] (part of the Extended Utilities Package[2]) run
 it on SDL.lib (I suppose it might work on SDL.dll.a), and link with the
 resulting converted file. Either that or compile SDL with DMC.

 Alternatively, you could modify your binding to load SDL dynamically
 like Derelict does. Then you don't need to fool around with any link
 libs. But, you do need a fair amount of implementation code to load the
 function symbols from the DLL.

 [1] http://www.digitalmars.com/ctg/coff2omf.html
 [2] http://www.digitalmars.com/download/freecompiler.html

The tool sounds cool but it seems that I have to buy it, so that's no option for me. So I tried to compile SDL myself. I have to say I'm to stupid for it. I tried to do the same thing as the makefile in powershell. After I hacked together some solution that worked dmc complained about missing Gl.h. It isn't there. So I added some MinGW to the include-path and then I get a bunch of errors in SDL without linenumbers. And anyways I am trying to compile it without MinGW, aren't I. Please, help me!

Just use Derelict and save yourself a world of grief. http://dsource.org/projects/derelict Compiling C libs with dmc is easy if you are an experenced C developer, but it's a nightmare if you aren't.
Aug 01 2010
prev sibling next sibling parent reply Mike Parker <aldacron gmail.com> writes:
Mafi wrote:

 The tool sounds cool but it seems that I have to buy it, so that's no 
 option for me. So I tried to compile SDL myself. I have to say I'm to 
 stupid for it. I tried to do the same thing as the makefile in 
 powershell. After I hacked together some solution that worked dmc 
 complained about missing Gl.h. It isn't there. So I added some MinGW to 
 the include-path and then I get a bunch of errors in SDL without 
 linenumbers. And anyways I am trying to compile it without MinGW, aren't 
 I. Please, help me!

I've converted it for you. You can download it here: http://aldacron.net/downloads/sdl.lib
Aug 01 2010
parent Mafi <mafi example.org> writes:
Am 02.08.2010 06:16, schrieb Mike Parker:
 Mafi wrote:

 The tool sounds cool but it seems that I have to buy it, so that's no
 option for me. So I tried to compile SDL myself. I have to say I'm to
 stupid for it. I tried to do the same thing as the makefile in
 powershell. After I hacked together some solution that worked dmc
 complained about missing Gl.h. It isn't there. So I added some MinGW
 to the include-path and then I get a bunch of errors in SDL without
 linenumbers. And anyways I am trying to compile it without MinGW,
 aren't I. Please, help me!

I've converted it for you. You can download it here: http://aldacron.net/downloads/sdl.lib

Thank you, but the download is corrupt for me. It's <1kb and most of it is '\0'. I downloaded objconv so I should be able to do it myself. Mafi
Aug 02 2010
prev sibling parent Mafi <mafi example.org> writes:
Am 02.08.2010 16:19, schrieb Trass3r:
 [1] http://www.digitalmars.com/ctg/coff2omf.html
 [2] http://www.digitalmars.com/download/freecompiler.html

The tool sounds cool but it seems that I have to buy it, so that's no option for me.

Yeah, it's a pity that such an important tool for D development on Windoze isn't free. You may try objconv though: http://www.agner.org/optimize/?e=0,24#objconv

Program compiles now but a get "object.Error: Access Violation" when I run it. Factored out it's the call to SDL_Init(). Is it because of the conversion (COFF -> ELF -> OMF; COFF -> OMF wasn't possible) or because of my wrong prototype export extern(C) { int SDL_Init(Uint32 flags); } BTW what does a Acces Violation mean? Mafi
Aug 03 2010
prev sibling next sibling parent Trass3r <un known.com> writes:
 [1] http://www.digitalmars.com/ctg/coff2omf.html
 [2] http://www.digitalmars.com/download/freecompiler.html

The tool sounds cool but it seems that I have to buy it, so that's no option for me.

Yeah, it's a pity that such an important tool for D development on Windoze isn't free. You may try objconv though: http://www.agner.org/optimize/?e=0,24#objconv
Aug 02 2010
prev sibling parent Trass3r <un known.com> writes:
 run it. Factored out it's the call to SDL_Init(). Is it because of the  
 conversion (COFF -> ELF -> OMF; COFF -> OMF wasn't possible) or because  
 of my wrong prototype
   export extern(C) { int SDL_Init(Uint32 flags); }
 BTW what does a Acces Violation mean?

Yep, unfortunately the objconv doesn't always work so good, probably because dmd uses a somewhat modified OMF IIRC. http://en.wikipedia.org/wiki/Access_violation
Aug 03 2010