compile: link dynamic OR static library in Windows

Richard (Rikki) Andrew Cattermole richard at
Mon Feb 6 08:23:37 UTC 2023

On 06/02/2023 8:43 PM, Alexander Zhirov wrote:
> Is it possible to collect all this from under mingw so that the linker 
> is not Microsoft, but `ld'?

Maybe. Keep in mind that mingw isn't the system toolchain, you'll 
probably run into issues using it else where. You should really be using 

We support the system toolchain solely pretty much.

So I just downloaded libpq from the site (64bit version for Windows, 

Copied lib+bin directory into working directory from the zip file.

alpha at DESKTOP-RB97SA4 /tmp/test_libpq
$ tree -L 1
├── bin
├── lib
├── test.d
├── test.exe
└── test.obj

2 directories, 3 files

Source file:

module test;
import std.stdio;

void main() {

     PGconn* conn = PQconnectdb("connection string");
     assert(conn !is null);


struct PGconn;

extern(C) {
     PGconn* PQconnectdb(const char *conninfo);
     void PQfinish(PGconn* conn);


alpha at DESKTOP-RB97SA4 /tmp/test_libpq
$ dmd -m64 lib/libpq.lib test.d

alpha at DESKTOP-RB97SA4 /tmp/test_libpq
$ PATH=$PATH:lib:bin ./test

I had to modify the PATH variable to setup the lib and bin directories 
for DLL lookup (bash syntax for Cygwin).

Appears to work fine.

More information about the Digitalmars-d-learn mailing list