Thread overview
linking in static c library
Mar 16, 2008
akcom
Mar 17, 2008
torhu
Mar 17, 2008
bearophile
March 16, 2008
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?
March 17, 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
March 17, 2008
akcom:
> 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

I think you may be ignorant about this matter, but I don't think you are stupid. Stupid people are the ones that don't want to learn, etc.

Bye,
bearophile