简体   繁体   English

带有 libpqxx-header 的 C++ 产生错误 C2039:“encoding_group”:不是“全局命名空间”的成员

[英]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 ).我做 PostGreSQL 查询已经 6 个月了,想用libpqxx做一些工作,我使用 DB 中的数据通过libpqxx访问(通过 vcpkg 获得的vcpkg )。

My environment is Visual Studio 2019. Properties-> C/C++ -> Language: ISO C++17 Standard (/std:c++17)我的环境是 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:在尝试编译我找到的示例时,当包含来自 include/pqxx/pqxx 的 array.hxx 时,出现以下错误:

------ 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.错误信息“'encoding_group': is not a member of '`global namespace”表示编译器在全局命名空间中找不到变量 encoding_group 的声明。 So my advice is to find the declaration of this encoding_group, and see where exactly this variable is declared所以我的建议是找到这个encoding_group的声明,看看这个变量到底是在哪里声明的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误C2039:&#39;result_type&#39;:不是&#39;`global namespace&#39;的成员 - error C2039: 'result_type' : is not a member of '`global namespace'' 错误C2039:&#39;memchr&#39;:不是&#39;`global namespace&#39;&#39;的成员 - error C2039: 'memchr' : is not a member of '`global namespace'' 错误 C2039:“fabs”:不是“全局命名空间”的成员 - error C2039: 'fabs': is not a member of '`global namespace'' 编译错误错误C2039:&#39;clock_t&#39;:不是&#39;`global namespace&#39;&#39;的成员 - Compilation error error C2039: 'clock_t' : is not a member of '`global namespace'' Visual Studio 2013:错误C2039:&#39;SetDefaultDllDirectories&#39;:不是&#39;`全局名称空间&#39;的成员 - Visual Studio 2013: error C2039: 'SetDefaultDllDirectories' : is not a member of '`global namespace'' 错误C2039:“ get_quest_dynstr”:不是“全局名称空间”的成员 - error C2039: 'get_quest_dynstr' : is not a member of '`global namespace' C2039:Class不是Namespace的成员 - C2039: Class is not a member of Namespace 错误C2039:&#39;string&#39;:不是&#39;std&#39;的成员,头文件有问题 - error C2039: 'string' : is not a member of 'std', header file problem 错误 C2039:“chrono”:不是“std”的成员 - error C2039: 'chrono': is not a member of 'std' 错误 C2039:“向量”:不是“标准”的成员 - ERROR C2039: 'vector': is not a member of 'std'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM