1

I have created a window using Dev-C++ as a windows application (not console application) and I want to access the PostgreSql database through my C++ code from the windows code for executing simple queries and display the result in that window. I tried searching on internet for connection codes but constantly getting errors and none worked.

I tried both the C and C++ codes and the respective procedures to connect. Can anyone help me get through this? Help is appreciated!

Humaira
  • 23
  • 8
  • There are many simple examples of PostgreSQL database connection on the internet like this [one](http://www.tutorialspoint.com/postgresql/postgresql_c_cpp.htm). What's the problem? – Erfan Aug 12 '15 at 05:55
  • I tried the same yesterday. I added libpxx. But when the code is run, it is showing 'there is no such directory named pqxx'. – Humaira Aug 12 '15 at 06:07
  • Are you using Visual Studio or GCC? – Erfan Aug 12 '15 at 06:08
  • Sorry, just noticed you had mentioned it already with Windows Application. The problem is you haven't set up the include directories right in your project. – Erfan Aug 12 '15 at 06:09
  • I added that 'pqxx' directory into it, still getting error – Humaira Aug 12 '15 at 06:11
  • Check [this question](https://stackoverflow.com/questions/257795/header-files-in-dev-c). Same type of error. [Here's](https://stackoverflow.com/questions/257795/header-files-in-dev-c) also another one addressing the problem with not found header files – Erfan Aug 12 '15 at 06:14
  • Just now I tried the steps in the given link. This is theerror I'm getting: [Error] ld returned 1 exit status – Humaira Aug 12 '15 at 06:37
  • Maybe [this](https://stackoverflow.com/questions/17717946/c-compile-error-id-returned-1-exit-status) is the issue? – Erfan Aug 12 '15 at 06:57
  • This is the error i am getting after adding pqxx directory : [Error] pqxx/binarystring: No such file or directory Compilation Terminated. Also getting 'pqxx file name not recognized' – Humaira Aug 12 '15 at 07:32

1 Answers1

0

The steps to access postgresql from applicaiton are

  1. Add "postgresql installation folder"\inclue directory to compile stage.
  2. Add "postgresql installation folder"\lib directory to linker stage.
  3. Add libpq.lib to linker stage.
  4. Copy libpq.dll from "postgresql installation folder"\lib to your applicaiton folder.
  5. Include "libpq-fe.h" in your project.

If you need any help about any step just comment.

I S
  • 436
  • 3
  • 7