Refering to Connect Postgresql in C
I asked some help to compile my script of Postgres database connection. This is now compiling well but now I have a problem when I execute it.
There is the code :
#include <stdio.h>
#include "libpq-fe.h"
#include <stdlib.h>
int main() {
PGconn *conn;
PGresult *res;
int rec_count;
int row;
int col;
conn = PQconnectdb("dbname=ljdata host=localhost user=dataman password=supersecret");
if (PQstatus(conn) == CONNECTION_BAD) {
puts("We were unable to connect to the database");
exit(0);
}
res = PQexec(conn,
"update people set phonenumber=\'5055559999\' where id=3");
res = PQexec(conn,
"select lastname,firstname,phonenumber from people order by id");
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
puts("We did not get any data!");
exit(0);
}
rec_count = PQntuples(res);
printf("We received %d records.\n", rec_count);
puts("==========================");
for (row=0; row<rec_count; row++) {
for (col=0; col<3; col++) {
printf("%s\t", PQgetvalue(res, row, col));
}
puts("");
}
puts("==========================");
PQclear(res);
PQfinish(conn);
return 0;
}
And this is the compilation line it's actually working :
gcc -m64 -I "C:\Program Files\PostgreSQL\9.6\include" -L "C:\Program Files\PostgreSQL\9.6\lib" test.c -lpq -o test.exe
Now when I double-click on the .exe I have the following error :
"Unable to start the program because LIBPQ.dll is missing"
So it clearly means that I have to link the libpq.dll
But what I'm trying to do is compiling all the methods from the .c/.dll etc in the binary .exe which I plan to distribute and the postgresql libs will not be installed on the target machines.
After some web search, I found the "-static" parameter but I'm not sure that it's what I'm looking for and I'm not able to have it compiling with this parameter.
Then I tried to add "-static-libgcc" which results as :
gcc -m64 -static-libgcc -I "C:\Program Files\PostgreSQL\9.6\include" -L "C:\Program Files\PostgreSQL\9.6\lib" test.c -lpq -o test.exe
But I still have the "System error" when I try to run it :
"Unable to run the script because LIBPQ.dll is missing on your computer" (Not sure if my french translate is exact)
Do you know the parameter or the way I can compile my C program into a binary .exe which would be totally standalone and without any library requirement ?
EDIT
Screenshot :