c++postgresqlvisual-studiocmakelibpqxx

namespace pqxx not recognized - Issues adding libpqxx to C++ Visual Studio PostgreSQL project on Windows


The Issue

I'm trying to use lipqxx to interact with a PostgreSQL database. However, despite #include-ing pqxx, its namespace doesn't seem to be recognized and as such no pqxx functions are recognized. (simplified code with annotations of issue below:)

#include <iostream>
#include <pqxx/pqxx> // no errors indicated in Visual Studio (VS) here. 

void Classname::operator() (){ // functor method implementation
    using namespace std;
    using namespace pqxx; // **red underline in Visual Studio indicating "name must be a namespace"**
    try{
        connection C("String text"); // **red underline in VS: "identifier 'connection' is undefined"**
    }catch(const std::exception &e) {
        cerr << e.what() << std::endl;
    }
}

What I've done

  1. Downloaded CMake (for Windows) and libpqxx.
  2. Built lipqxx using CMake following instructions in (this video: https://www.youtube.com/watch?v=LxHV-KNEG3k). This produced a folder called "libpqxx" which has "bin", "include", "lib" and "share" sub-folders.
  3. Followed instructions (on this thread: How to add additional libraries to Visual Studio project?) to add the built libraries to my VS project

Conclusion

I'd like the pqxx namespace to be properly recognized and am not sure where to go from here. I've been stuck on this for quite a while and would really appreciate some clear guiding steps on how to fix this.

Many thanks


Solution

  • I had the same problem after running:

    vcpkg install libqpxx:x64-windows
    

    Running (as administrator)

    vcpkg integrate install
    

    solved the issue for me