linking in static c library

torhu no at spam.invalid
Sun Mar 16 17:17:57 PDT 2008


akcom wrote:
> I've got some cipher/hashing routines (AES, RSA, and SHA256, not that it matters) that are written C.  I'd like to compile them into a static library so that I can basically wrap it in D bindings and use it in my application.  Feel free to correct me if I'm wrong, but I'm under the impression that I must compile my C static library with the digitalmars C compiler.  Unfortunately having come from Visual C++ 6.0, I'm not very well adept at console compiling/linking.  I feel quite stupid asking this, but could someone explain to me how I can build a static library in C that can be used in a D project?

Yes, you need to use dmc.  msvc uses a different object file format. 
You compile the files with dmc, then use the lib tool if you want to 
collect in a static link library.  A static link library is really just 
an archive of object files, with an index telling the linker which 
object file contains which symbols.

Here are some sample command lines:

dmc -c file1.c file2.c
lib -c mylib file1 file2

Then you can do:

dmd myapp mylib.lib


And it'll be like linking with file1.obj and file2.obj.

docs for lib:
http://www.digitalmars.com/ctg/lib.html


More information about the Digitalmars-d-learn mailing list