Link against a 3rd-party library with Visual Studio

前端 未结 3 1111
Happy的楠姐
Happy的楠姐 2020-12-12 02:57

I\'m trying to create a .dll with Visual Studios 2013. The project includes libpq functionality.

Per other stackoverflow posts, and other sources I\'ve found on the

相关标签:
3条回答
  • 2020-12-12 03:20

    I've successfully compiled the sample program by setting these project properties:

    • Add <pgsql install path>\include and \lib to VC++ Directories->Include and ->Library, correspondingly
    • Add libpq.lib to Linker->Input->Additional dependencies

    This is the standard way to reference 3rd-party libs. It's just that they recommend using environment variables for their "base dirs" to avoid patching the project when it's under a VCS.

    • To be able to run the app from VS (both with and without debugging), I also specified PATH=%PATH%;<pgsql install path>\bin in Debugging->Environment since this dir isn't in PATH on my system.
    0 讨论(0)
  • 2020-12-12 03:36

    It's not sufficient add the postgres lib directory to the project, you must also add reference to libpq.lib. Just add this line to one of your source .cpp files:

    #pragma comment(lib, "libpq.lib")
    

    As noted by Marco A. the library must match a program bitness (32 or 64 bit): if you build 32-bit DLL (referred as Win32) you must use 32 bit library; if 64-bit (x64) - 64-bit library.

    0 讨论(0)
  • 2020-12-12 03:37

    I have also faced same issue. Then I realized that I was building my application as a 32bit. I changed the target of my application to x64 and it compiled successfully

    0 讨论(0)
提交回复
热议问题