On Sunday, 15 August 2021 at 10:05:15 UTC, Mike Parker wrote:
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.

Thank you for your reply!
I wanted to link to my project another project without source code.

Reply via email to