February 06, 2023

On Monday, 6 February 2023 at 05:45:35 UTC, Richard (Rikki) Andrew Cattermole wrote:

>

Ah doh, MSVC link doesn't use -L.

$ dmd -i "-L/LIBPATH:C:\Program Files\PostgreSQL\15\lib" -Llpq app.d

I think that is the option you want.

Worst case scenario just copy the files to your working directory and it should find it without the additional search path.

He doesn't want to anyway. I have already put the library in the source code folder. But it still pulls up the *.obj format for some reason.

C:\sources\pxe-restore\source>ls
app.d  app.obj  arsd  azh  libpq.lib  pkg

C:\sources\pxe-restore\source>dmd -i "-L/LIBPATH:C:\Program Files\PostgreSQL\15\lib" -Llpq app.d
LINK : fatal error LNK1181: не удается открыть входной файл "lpq.obj"
Error: linker exited with status 1181

C:\sources\pxe-restore\source>dmd -i "-L/LIBPATH:C:\sources\pxe-restore\source" -Llpq app.d
LINK : fatal error LNK1181: не удается открыть входной файл "lpq.obj"
Error: linker exited with status 1181
February 06, 2023
On other platforms the -Lfile I think would work.

On Windows you have to link against the import library not DLL directly.

You can pass it to the compiler:

$ dmd -i "-L/LIBPATH:C:\Program Files\PostgreSQL\15\lib" pq.lib app.d

Should work. Sorry, I should have revisted this from the get go, rather than just tinkering with what others were posting.
February 06, 2023

On Monday, 6 February 2023 at 06:59:09 UTC, Richard (Rikki) Andrew Cattermole wrote:

>

On other platforms the -Lfile I think would work.

On Windows you have to link against the import library not DLL directly.

You can pass it to the compiler:

$ dmd -i "-L/LIBPATH:C:\Program Files\PostgreSQL\15\lib" pq.lib app.d

Should work. Sorry, I should have revisted this from the get go, rather than just tinkering with what others were posting.

It doesn't work anyway...

Is it possible to collect all this from under mingw so that the linker is not Microsoft, but `ld'?

February 06, 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@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@DESKTOP-RB97SA4 /tmp/test_libpq
$ dmd -m64 lib/libpq.lib test.d

alpha@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.
February 06, 2023

On Monday, 6 February 2023 at 08:23:37 UTC, Richard (Rikki) Andrew Cattermole wrote:

>

[...]

Yes, your solution works. I apologize for my inattention. I should have checked earlier in your way. Most likely Adam has a problem with linking in the library.

1 2
Next ›   Last »