www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - how to use a lib in d

reply maarten van damme <maartenvd1994 gmail.com> writes:
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
Mar 27 2011
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
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
=20 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:
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?
Mar 27 2011
prev sibling next sibling parent maarten van damme <maartenvd1994 gmail.com> writes:
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.
Mar 28 2011
prev sibling parent reply 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
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 reply 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
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