Can PostgreSQL ECPG programs be compiled on Windows OS?

70 Views Asked by At

I have installed PostgreSQL v15.5 on Windows 11, so I got the ECPG library (libecpg.dll, libecpg.lib) in path C:\Program Files\PostgreSQL\15\lib: enter image description here

Then I try to compile an ECPG program on it, so I also installed the MinGW gcc compiler. enter image description here

Here is a very simple ECPG program (example01.pgc):

#include <stdio.h>
#include <stdlib.h>

void main()
{
  exec sql begin declare section;
    int sum;  /* host variable */
  exec sql end declare section;

  exec sql connect to 'postgres';  /* connect to postgres DB */
  exec sql select 1 + 1 into :sum;
  printf("sum = %d\n", sum);
}

But when I start to compile this ECPG program, it always fail.

E:\ecpg>ecpg example01.pgc

E:\ecpg>gcc -I"C:\\Program Files\\PostgreSQL\\15\\include" -c example01.c

E:\ecpg>gcc -L"C:\\Program Files\\PostgreSQL\\15\\lib\\libecpg.dll" -o example01 example01.o
example01.o:example01.c:(.text+0x46): undefined reference to `ECPGconnect'
example01.o:example01.c:(.text+0xe2): undefined reference to `ECPGdo'
collect2.exe: error: ld returned 1 exit status

E:\ecpg>gcc -L"C:\\Program Files\\PostgreSQL\\15\\lib\\libecpg.lib" -o example01 example01.o
example01.o:example01.c:(.text+0x46): undefined reference to `ECPGconnect'
example01.o:example01.c:(.text+0xe2): undefined reference to `ECPGdo'
collect2.exe: error: ld returned 1 exit status

But when I compile the same code in Linux OS, it works.

Is it impossible to compile the ECPG program on Windows OS? How to make it work? Thanks.

0

There are 0 best solutions below