www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - how to use a lib in d

reply maarten van damme <maartenvd1994 gmail.com> writes:
--001636b2bc3879c7e0049f7c5170
Content-Type: text/plain; charset=ISO-8859-1

Hello everyone,
I've succesfully compiled the win32.lib file from the bindings project.
For a fun little project I need to call the windows function
"writeprocessmemory/readprocessmemory" in winbase.d .
I loved to use the eclipse ide to use with it but I kept getting the same
error over and over again so I installed the entice ide.
This gave more control over the compile command. But the error persisted.

*"Error module winbase is in file win32/winbase.d which cannot be found..."*
The contents of the file I'm trying to compile:

*"pragma(lib,"win32.lib");*
*
*
*import win32.winbase;"*

The compile command is:
*"dmd.exe common.d main.d win32.lib -ofediting.exe -inline -O -release -w
-version=Unicode -version=WindowsVista"*
*
*
So it looks as if the modules from win32.lib do not get used when I try to
import.

Thanks in advance,
Maarten

--001636b2bc3879c7e0049f7c5170
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hello everyone,
<div>I&#39;ve succesfully compiled the win32.lib file from the bindings pro=
ject.=A0</div><div>For a fun little project I need to call the windows func=
tion &quot;writeprocessmemory/readprocessmemory&quot; in winbase.d .</div>
<div>I loved to use the eclipse ide to use with it but I kept getting the s=
ame error over and over again so I installed the entice ide.=A0</div><div>T=
his gave more control over the compile command. But the error persisted.</d=
iv>
<div><br></div><div><i>&quot;Error module winbase is in file win32/winbase.=
d which cannot be found...&quot;</i></div><div>The contents of the file I&#=
39;m trying to compile:</div><div><br></div><div><i>&quot;pragma(lib,&quot;=
win32.lib&quot;);</i></div>
<div><i><br></i></div><div><i>import win32.winbase;&quot;</i></div><div><br=
</div><div>The compile command is:</div><div><i>&quot;dmd.exe common.d mai=

sion=3DWindowsVista&quot;</i></div> <div><i><br></i></div><div>So it looks as if the modules from win32.lib do = not get used when I try to import.</div><div><br></div><div>Thanks in advan= ce,</div><div>Maarten</div> --001636b2bc3879c7e0049f7c5170--
Mar 27 2011
next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2011-03-27 22:03, maarten van damme wrote:
 Hello everyone,
 I've succesfully compiled the win32.lib file from the bindings project.
 For a fun little project I need to call the windows function
 "writeprocessmemory/readprocessmemory" in winbase.d .
 I loved to use the eclipse ide to use with it but I kept getting the
 same error over and over again so I installed the entice ide.
 This gave more control over the compile command. But the error persisted.

 /"Error module winbase is in file win32/winbase.d which cannot be found..."/
 The contents of the file I'm trying to compile:

 /"pragma(lib,"win32.lib");/
 /
 /
 /import win32.winbase;"/

 The compile command is:
 /"dmd.exe common.d main.d win32.lib -ofediting.exe -inline -O -release
 -w -version=Unicode -version=WindowsVista"/
 /
 /
 So it looks as if the modules from win32.lib do not get used when I try
 to import.

 Thanks in advance,
 Maarten

Seems the compiler can't find win32.winbase. Add this to compile command: -I/path/to/parent_of_win32 Example: say that winbase.d is located at: C:\d\imports\win32\winbase.d Then add this to the command: -IC:\d\imports -- /Jacob Carlborg
Mar 27 2011
parent reply Mafi <mafi example.org> writes:
Am 28.03.2011 19:48, schrieb Andrew Wiley:
 On Mon, Mar 28, 2011 at 12:34 PM, maarten van damme
 <maartenvd1994 gmail.com>  wrote:
 Thanks to everyone, I got it to compile :D

 Still don't get the point of a lib file. I'm used to program java and there
 you can compile to a jar-libary, a lib in d is obviously not the same.

In a machine-compiled language, a library just contains straight binary, and you need a header or an import file (di) to tell the compiler exactly what code is in that library. This is because unlike Java, where type information is preserved in bytecode, machine-compiled code loses a lot of type information during the transition from code to binary. For example, if I have void add(int a, uint b) and I compile it, I can no longer tell you that a and b have different types. At least, this is how I understand it.

AFAIK you can't get any parameter type from just-binary. The code in there just expects the stack to have a certain structure and fullfil certain consitions. If these conditions are not fullfilled it'll probaly segfault. Because D (like C++ and unlike C) allows overloading the same name on different parameter types, this information has to be put into the name (mangling) to avoid name clashes for the linker. Mafi PS: Just a thought of mine: You should be theoretically be able regenereate function signatures from mangled names. Maybe someone could such a tool.
Mar 28 2011
parent Adam D. Ruppe <destructionator gmail.com> writes:
Mafi wrote:
 PS: Just a thought of mine: You should be theoretically be able
 regenereate function signatures from mangled names. Maybe someone
 could such a tool.

import core.demangle; http://digitalmars.com/d/2.0/phobos/std_demangle.html If you did a mixin(demangle(fname)) you actually should be able to make it work from a lib in most cases. There's a lot of mangled names that can't be unmangled though, so it won't be perfect.
Mar 28 2011
prev sibling next sibling parent Maarten <maartenvd1994 gmail.com> writes:
Wow, thank you for the fast reply.
Winbase.d is compiled in win32.lib or am i really getting confused?




Op 27-mrt.-2011 om 22:25 heeft Jacob Carlborg <doob me.com> het volgende ges=
chreven:

 On 2011-03-27 22:03, maarten van damme wrote:
 Hello everyone,
 I've succesfully compiled the win32.lib file from the bindings project.
 For a fun little project I need to call the windows function
 "writeprocessmemory/readprocessmemory" in winbase.d .
 I loved to use the eclipse ide to use with it but I kept getting the
 same error over and over again so I installed the entice ide.
 This gave more control over the compile command. But the error persisted.=


=20
 /"Error module winbase is in file win32/winbase.d which cannot be found..=


 The contents of the file I'm trying to compile:
=20
 /"pragma(lib,"win32.lib");/
 /
 /
 /import win32.winbase;"/
=20
 The compile command is:
 /"dmd.exe common.d main.d win32.lib -ofediting.exe -inline -O -release
 -w -version=3DUnicode -version=3DWindowsVista"/
 /
 /
 So it looks as if the modules from win32.lib do not get used when I try
 to import.
=20
 Thanks in advance,
 Maarten

Seems the compiler can't find win32.winbase. Add this to compile command: =20 -I/path/to/parent_of_win32 =20 Example: =20 say that winbase.d is located at: =20 C:\d\imports\win32\winbase.d =20 Then add this to the command: =20 -IC:\d\imports =20 --=20 /Jacob Carlborg

Mar 27 2011
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
--000e0cd72dec8b893d049f841b3f
Content-Type: text/plain; charset=ISO-8859-1

So what's the point of compiling all those files to a lib if you can't use
that lib anymore?
Is there some documentation on this?

--000e0cd72dec8b893d049f841b3f
Content-Type: text/html; charset=ISO-8859-1

So what&#39;s the point of compiling all those files to a lib if you can&#39;t
use that lib anymore?<br>Is there some documentation on this?<br>

--000e0cd72dec8b893d049f841b3f--
Mar 27 2011
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
--000e0cd72dece4e374049f8e5a5e
Content-Type: text/plain; charset=ISO-8859-1

Thanks to everyone, I got it to compile :D

Still don't get the point of a lib file. I'm used to program java and there
you can compile to a jar-libary, a lib in d is obviously not the same.

--000e0cd72dece4e374049f8e5a5e
Content-Type: text/html; charset=ISO-8859-1

Thanks to everyone, I got it to compile :D<br><br>Still don&#39;t get the point
of a lib file. I&#39;m used to program java and there you can compile to a
jar-libary, a lib in d is obviously not the same. <br>

--000e0cd72dece4e374049f8e5a5e--
Mar 28 2011
prev sibling next sibling parent Andrew Wiley <debio264 gmail.com> writes:
On Mon, Mar 28, 2011 at 12:34 PM, maarten van damme
<maartenvd1994 gmail.com> wrote:
 Thanks to everyone, I got it to compile :D

 Still don't get the point of a lib file. I'm used to program java and there
 you can compile to a jar-libary, a lib in d is obviously not the same.

In a machine-compiled language, a library just contains straight binary, and you need a header or an import file (di) to tell the compiler exactly what code is in that library. This is because unlike Java, where type information is preserved in bytecode, machine-compiled code loses a lot of type information during the transition from code to binary. For example, if I have void add(int a, uint b) and I compile it, I can no longer tell you that a and b have different types. At least, this is how I understand it.
Mar 28 2011
prev sibling parent Maarten <maartenvd1994 gmail.com> writes:
Yoohoo, i got eclipse working with it an compiled without errors.=20

So if i understand it correctly a .h/.di file contains the info abou what's c=
ompiled in the lib so you can use it, sounds logical :)

And about eclipse: when i let him autocomplete when i haven't typed anything=
 it freezes for 2 minutes. My guess is that it loads all sugestions in one t=
ime (instead for example the first 20) causing everything to freeze?
Where can i inform the maintainers (apart from the forums)? There are like 4=
 different plugins and i don't know which one i'm using. It's the not-abondo=
ned one :)

And is the ide on dprogramminglanguage.com still maintained?=20

Thanks to all the help so far=
Mar 28 2011