C ++ с заголовком libpqxx выдает ошибку C2039: «encoding_group»: не является членом «глобального пространства имен» - PullRequest
0 голосов
/ 25 октября 2019

Я выполняю запросы PostGreSQL уже 6 месяцев и хотел использовать libpqxx для выполнения некоторой работы, где я использовал данные из БД для доступа через libpqxx (V6. 4.5, полученный через vcpkg).

Моя среда - Visual Studio 2019. Properties-> C/C++ -> Language : ISO C++17 Standard (/std:c++17)

При попытке скомпилировать найденный мной пример я получаю следующую ошибку, когда array.hxx из include/ pqxx / pqxx включено:

------ 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 ==========

Вот код, который я пытаюсь скомпилировать:

#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;
  }
}

Кто-нибудь еще сталкивался с этим ??

1 Ответ

0 голосов
/ 25 октября 2019

Сообщение об ошибке «encoding_group»: не является членом «глобального пространства имен» означает, что компилятор не может найти объявление переменной encoding_group в глобальном пространстве имен. Поэтому я советую найти объявление этой группы encoding_group и посмотреть, где именно объявлена ​​эта переменная

...