www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Q: how to get C code to work in D?

reply Hoenir <mrmocool gmx.de> writes:
I got a C file (it's a library, so in C you would create a static 
library and link it to another program) I want to use in D.
I already created the necessary d file as described here:
http://www.digitalmars.com/d/interfaceToC.html

But how do I link the C code? dmd isn't able to compile C files.

I know how to get a dll working (creating C dll, corresponding lib with 
implib and then adding that lib to the command line of dmd) but I want 
it to be statically linked like in C.
Any hints?
Jun 12 2007
next sibling parent reply BCS <ao pathlink.com> writes:
Reply to Hoenir,

 I got a C file (it's a library, so in C you would create a static
 library and link it to another program) I want to use in D.
 I already created the necessary d file as described here:
 http://www.digitalmars.com/d/interfaceToC.html
 But how do I link the C code? dmd isn't able to compile C files.
 
 I know how to get a dll working (creating C dll, corresponding lib
 with
 implib and then adding that lib to the command line of dmd) but I want
 it to be statically linked like in C.
 Any hints?

Download dmc (the digital mars C compiler) and build the lib with that. Then pass the .obj's or .lib to dmd with everything else. Or use link.exe directly.
Jun 12 2007
next sibling parent Myron Alexander <someone somewhere.com> writes:
BCS wrote:
 Reply to Hoenir,
 
 I got a C file (it's a library, so in C you would create a static
 library and link it to another program) I want to use in D.
 I already created the necessary d file as described here:
 http://www.digitalmars.com/d/interfaceToC.html
 But how do I link the C code? dmd isn't able to compile C files.

 I know how to get a dll working (creating C dll, corresponding lib
 with
 implib and then adding that lib to the command line of dmd) but I want
 it to be statically linked like in C.
 Any hints?

Download dmc (the digital mars C compiler) and build the lib with that. Then pass the .obj's or .lib to dmd with everything else. Or use link.exe directly.

If you already have an obj file but it won't link, it could be that the obj format is not compatible with the obj format used by digital mars, in which case you can use one of the converters. I do not know the digital mars tool-chain but I am sure that someone else has had to solve this problem so it will be in the archives. Regards, Myron.
Jun 12 2007
prev sibling parent reply Hoenir <mrmocool gmx.de> writes:
BCS schrieb:
 Reply to Hoenir,
 
 I got a C file (it's a library, so in C you would create a static
 library and link it to another program) I want to use in D.
 I already created the necessary d file as described here:
 http://www.digitalmars.com/d/interfaceToC.html
 But how do I link the C code? dmd isn't able to compile C files.

 I know how to get a dll working (creating C dll, corresponding lib
 with
 implib and then adding that lib to the command line of dmd) but I want
 it to be statically linked like in C.
 Any hints?

Download dmc (the digital mars C compiler) and build the lib with that. Then pass the .obj's or .lib to dmd with everything else. Or use link.exe directly.

I tried dmc -c main.c dmd test.d main.obj which didn't fix the Symbol Undefined error.
Jun 12 2007
parent reply BCS <ao pathlink.com> writes:
Reply to Hoenir,

 BCS schrieb:
 
 Reply to Hoenir,
 
 I got a C file (it's a library, so in C you would create a static
 library and link it to another program) I want to use in D.
 I already created the necessary d file as described here:
 http://www.digitalmars.com/d/interfaceToC.html
 But how do I link the C code? dmd isn't able to compile C files.
 I know how to get a dll working (creating C dll, corresponding lib
 with
 implib and then adding that lib to the command line of dmd) but I
 want
 it to be statically linked like in C.
 Any hints?

that. Then pass the .obj's or .lib to dmd with everything else. Or use link.exe directly.

dmc. I tried dmc -c main.c dmd test.d main.obj which didn't fix the Symbol Undefined error.

could you post a short example?
Jun 12 2007
parent Hoenir <mrmocool gmx.de> writes:
BCS schrieb:
 Reply to Hoenir,
 
 BCS schrieb:

 Reply to Hoenir,

 I got a C file (it's a library, so in C you would create a static
 library and link it to another program) I want to use in D.
 I already created the necessary d file as described here:
 http://www.digitalmars.com/d/interfaceToC.html
 But how do I link the C code? dmd isn't able to compile C files.
 I know how to get a dll working (creating C dll, corresponding lib
 with
 implib and then adding that lib to the command line of dmd) but I
 want
 it to be statically linked like in C.
 Any hints?

that. Then pass the .obj's or .lib to dmd with everything else. Or use link.exe directly.

dmc. I tried dmc -c main.c dmd test.d main.obj which didn't fix the Symbol Undefined error.

could you post a short example?

imported by test.d
Jun 12 2007
prev sibling parent reply Hoenir <mrmocool gmx.de> writes:
Hoenir schrieb:
 I got a C file (it's a library, so in C you would create a static 
 library and link it to another program) I want to use in D.
 I already created the necessary d file as described here:
 http://www.digitalmars.com/d/interfaceToC.html
 
 But how do I link the C code? dmd isn't able to compile C files.
 
 I know how to get a dll working (creating C dll, corresponding lib with 
 implib and then adding that lib to the command line of dmd) but I want 
 it to be statically linked like in C.
 Any hints?

files, which switch do I need to create a lib?
Jun 12 2007
parent reply BCS <ao pathlink.com> writes:
Reply to Hoenir,

 Hoenir schrieb:
 
 I got a C file (it's a library, so in C you would create a static
 library and link it to another program) I want to use in D.
 I already created the necessary d file as described here:
 http://www.digitalmars.com/d/interfaceToC.html
 But how do I link the C code? dmd isn't able to compile C files.
 
 I know how to get a dll working (creating C dll, corresponding lib
 with
 implib and then adding that lib to the command line of dmd) but I
 want
 it to be statically linked like in C.
 Any hints?

several files, which switch do I need to create a lib?

I think their is a lib.exe next to dmc http://www.digitalmars.com/ctg/lib.html
Jun 12 2007
next sibling parent Daniel Keep <daniel.keep.lists gmail.com> writes:
IIRC, you can generate a static library simply by not having a main
function anywhere in your program.

At least, that's what happens when I forget to link in the module with
main in it :P

	-- Daniel
Jun 12 2007
prev sibling parent Hoenir <mrmocool gmx.de> writes:
BCS schrieb:
 Reply to Hoenir,
 
 Hoenir schrieb:

 I got a C file (it's a library, so in C you would create a static
 library and link it to another program) I want to use in D.
 I already created the necessary d file as described here:
 http://www.digitalmars.com/d/interfaceToC.html
 But how do I link the C code? dmd isn't able to compile C files.

 I know how to get a dll working (creating C dll, corresponding lib
 with
 implib and then adding that lib to the command line of dmd) but I
 want
 it to be statically linked like in C.
 Any hints?

several files, which switch do I need to create a lib?

I think their is a lib.exe next to dmc http://www.digitalmars.com/ctg/lib.html

Jun 13 2007