简体   繁体   中英

C++ with libpqxx-header produces error C2039: 'encoding_group': is not a member of '`global namespace''

I have been doing PostGreSQL queries for 6 months now, and wanted to use libpqxx to do some work, where I used the data from DB to access through libpqxx (V6.4.5 obtained through vcpkg ).

My environment is Visual Studio 2019. Properties-> C/C++ -> Language: ISO C++17 Standard (/std:c++17)

On trying to compile the example I found, I get following error, when array.hxx from include/pqxx/pqxx is included:

------ Build started: Project: pqxx-test2, Configuration: Debug Win32 ------
1>pqxx-test2.cpp
1>C:\Users\olebe\OneDrive\Documents\Projects\vcpkg\packages\libpqxx_x86-windows\include\pqxx\array.hxx(66,62): error C2039: 'encoding_group': is not a member of '`global namespace''
1>Done building project "pqxx-test2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Here is the code, that I try to compile:

#include <iostream>
#include <pqxx/pqxx>

/// Query employees from database.  Return result.
pqxx::result query()
{
    pqxx::connection c{ "postgresql://accounting@localhost/company" };
    pqxx::work txn{ c };

pqxx::result r = txn.exec("SELECT name, salary FROM Employee");
for (auto row : r)
std::cout
// Address column by name.  Use c_str() to get C-style string.
<< row["name"].c_str()
<< " makes "
// Address column by zero-based index.  Use as<int>() to parse as int.
<< row[1].as<int>()
<< "."
<< std::endl;

// Not really needed, since we made no changes, but good habit to be
// explicit about when the transaction is done.
txn.commit();

// Connection object goes out of scope here.  It closes automatically.
return r;
}


/// Query employees from database, print results.
int main(int, char* argv[])
{
  try
  {
    pqxx::result r = query();

    // Results can be accessed and iterated again.  Even after the connection
    // has been closed.
    for (auto row : r)
    {
      std::cout << "Row: ";
      // Iterate over fields in a row.
      for (auto field : row) std::cout << field.c_str() << " ";
      std::cout << std::endl;
    }
  }
  catch (const pqxx::sql_error & e)
  {
    std::cerr << "SQL error: " << e.what() << std::endl;
    std::cerr << "Query was: " << e.query() << std::endl;
    return 2;
  }
  catch (const std::exception & e)
  {
    std::cerr << "Error: " << e.what() << std::endl;
    return 1;
  }
}

Has somebody else come across this??

The error message " 'encoding_group': is not a member of '`global namespace" means that the compiler can't find the declaration of the variable encoding_group in the global namespace. So my advice is to find the declaration of this encoding_group, and see where exactly this variable is declared

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