how to import .lib library
Mike Parker
aldacron at gmail.com
Sun Aug 15 10:05:15 UTC 2021
On Sunday, 15 August 2021 at 09:49:39 UTC, Timofeyka wrote:
> Hello!
> I may have a very stupid question, but still.
> How do I include a .lib library? How to use it in your code?
You don't import a .lib file. They are for the linker, not the
compiler. How you make use of it depends on what sort of library
it is and how you're building your project.
If this is all new to you, it will be easier just to specify here
which library it is that you're wanting to use, then I or someone
else can give you directions. But the general idea is as follows.
If it's a D library, you'll need access to the source code (or
alternatively, D interface files that have a .di extension, but
that's another topic). That's what you use at compile time via
the `import` statement. When you import, for example,
`std.stdio`, you are importing the module from the Phobos source
tree that ships with the compiler.
If the library is registered with the dub repository, then you
can use dub to manage and build your project to make life easier.
The library's source will be available to import, and dub will
build the library and make sure it's linked.
If the library is not registered with dub, you'll need to
download the source somewhere, make sure it's on the import path
(use the `-I` switch on the compiler command line with the source
path, e.g., `-I/path/to/source`), you'll need to make sure the
library is compiled separately from your project, and then you'll
need to give the lib file to the compiler on the command line
along with your source (e.g., `dmd app.d library.lib`).
If it's a C library, you'll need to translate the C API to D (not
the source code, just the type and function declarations) if it
hasn't been done already. Then you import the translated D files
and give the .lib file to the compiler as above.
More information about the Digitalmars-d-learn
mailing list