<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><div>Hola, buenas tardes</div><div><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">Estoy tratando de hacer funcionar un programa simple que se conecta a Postgres usando la librería LIBPQ. El programa es el siguiente:</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">CONEXION_PG.CPP</div><div
 style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="background-color: transparent;">#include <iostream></div><div style="background-color: transparent;">#include "libpq-fe.h"</div><div style="background-color: transparent;">#include <stdio.h></div><div style="background-color: transparent;">using namespace std;</div><div style="background-color: transparent;"><br></div><div style="background-color: transparent;">char pghost[] = "localhost";</div><div style="background-color: transparent;">char pgport[] = "5432";</div><div style="background-color: transparent;">char pgbase[] = "bdprueba";</div><div style="background-color: transparent;">char pguser[] = "postgres";</div><div style="background-color: transparent;">char pgpass[] = "123456";</div><div style="background-color:
 transparent;">char conninf[] = "host=localhost port=5432 database=postgres user=postgres password=123456";</div><div style="background-color: transparent;"><br></div><div style="background-color: transparent;">int main(){</div><div style="background-color: transparent;"><span class="" style="white-space:pre">     </span>PGconn *conn = PQsetdbLogin(pghost,pgport,NULL,NULL,pgbase,pguser,pgpass);</div><div style="background-color: transparent;"><br></div><div style="background-color: transparent;"><span class="" style="white-space:pre">      </span>if (PQstatus(conn) == CONNECTION_OK)</div><div style="background-color: transparent;"><span class="" style="white-space:pre">      </span>{</div><div style="background-color: transparent;"><span class="" style="white-space:pre">         </span>//if connected</div><div style="background-color: transparent;"><span class="" style="white-space:pre">            </span>cout<<"Ok.\n";</div><div style="background-color: transparent;"><span
 class="" style="white-space:pre">       </span>}</div><div style="background-color: transparent;"><span class="" style="white-space:pre"> </span>else</div><div style="background-color: transparent;"><span class="" style="white-space:pre">              </span>{</div><div style="background-color: transparent;"><span class="" style="white-space:pre">                 </span>cout<<"ERROR: %s\n";</div><div style="background-color: transparent;"><span class="" style="white-space:pre">                      </span>PQfinish(conn);</div><div style="background-color: transparent;"><span class="" style="white-space:pre">           </span>}</div><div style="background-color: transparent;"><span class="" style="white-space:pre"> </span>return 0;</div><div style="background-color: transparent;">}</div><div style="background-color: transparent;"><br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande',
 sans-serif; font-style: normal;">- La plataforma sobre la que trabajo es Windows7 64bits</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;">- El compilador que estoy usando es MinGW 5.1.6</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;"><br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;">- Compilé el programa sin ningún error de la siguiente forma:</div><div style="background-color: transparent;">mingw32-g++ -o D:\practicas_c++\conexion_bd_pg\conexion_pg.exe D:\practicas_c++\conexion_bd_pg\conexion_pg.cpp
 -ID:\PostgreSQL\9.2\include -LD:\PostgreSQL\9.2\lib -lpq<br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;"><br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;">- Al ejecutar  <span style="font-size: 12pt;">conexion_pg.</span><span style="background-color: transparent;">exe, windows me muestra un mensaje de error:</span></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;"><span class="Apple-tab-span" style="white-space:pre">     </span>La aplicación no se pudo iniciar correctamente (0xc000007b). Haga clic
 en Aceptar para cerrarla</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;"><br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;">Nota: como trabajo con postgres sobre windows, no existía el archivo libpq.a por lo que tuve que generarlo a a partir de libpq.dll siguiendo unos pasos que encontré en internet:</div><div style="background-color: transparent;"><span class="Apple-tab-span" style="color: rgb(0, 0, 0); font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 16px; font-style: normal; white-space: pre;">      </span>Primero D:\PostgreSQL\9.2\lib>reimp -d libpq.lib</div><div style="background-color:
 transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;"><span class="Apple-tab-span" style="white-space:pre">   </span>Luego D:\PostgreSQL\9.2\lib>dlltool --input-def libpq.def --dllname libpq.dll --output-lib libpq.a -k</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;"><br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;">Ojalá que alguien puede ayudarme con este problema ya que tengo varios días sin poder encontrar la solución, desde ya agradezco la ayuda que me puedan brindar.</div><div style="background-color: transparent; color: rgb(0,
 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;"><br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;">Atte.</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;"><br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style: normal;">Walter</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-style:
 normal;"><br></div></div></body></html>