简体   繁体   中英

Linking to and using libpq with Visual C++ Express 2010

I am trying to access from Visual C++ 2010 Express a Postgres database. I have both on my machine but the SQL calls do not work at all. I have searched many sites. I think that this version of Express does not have any default database connections like the non-express version (especially Visual C++ 2008).

The only thing I could find was the following link and I have following the modifications to the Project Properties area of Visual C++ Express.

http://www.askyb.com/cpp/c-postgresql-example/

When I try to run the C++ code in that website I get errors indicating that it cannot find the functions.

Do you have any ideas of what I am doing wrong? Would it be better for me to use something other than Visual C++ Express 2010 to connect to a postgres db? One of the other Express versions? The regular (non-express) Visual C++?

Thanks

You may also be interested in libpqtypes and libpqxx if you're working with PostgreSQL and libpq. The first provides greatly simplified access to data values from libpq, and the latter provides a more C++-friendly interface.

As for the errors, most likely:

  • Your include path or link library path is wrong if it's failing at compile-time or link time; or
  • Your PATH doesn't include libpq, if it's failing at runtime.

Most likely (you didn't provide any actual error messages) the problem is your setup. You need to add the correct header ("include") directory and library directory; if you just copied them from some tutorial, make sure they actually point to the real place where these files (.h and .lib files, respectively) are.

您需要使用MSVC(nmake / f win32.mak all)重新编译libpq,之后,您需要将项目设置为使用该库,并将公共语言运行时支持更改为(/ clr)而不是clr / pure 。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM