compile: link dynamic OR static library in Windows
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
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
MSVC.
We support the system toolchain solely pretty much.
So I just downloaded libpq from the site (64bit version for Windows,
15.1). https://www.enterprisedb.com/download-postgresql-binaries
Copied lib+bin directory into working directory from the zip file.
```sh
alpha at DESKTOP-RB97SA4 /tmp/test_libpq
$ tree -L 1
.
├── bin
├── lib
├── test.d
├── test.exe
└── test.obj
2 directories, 3 files
```
Source file:
```d
module test;
import std.stdio;
void main() {
writeln("start");
PGconn* conn = PQconnectdb("connection string");
assert(conn !is null);
PQfinish(conn);
writeln("end");
}
struct PGconn;
extern(C) {
PGconn* PQconnectdb(const char *conninfo);
void PQfinish(PGconn* conn);
}
```
Output:
```sh
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
start
end
```
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