【问题标题】:No pqxx::tuple in libpqxx library?libpqxx 库中没有 pqxx::tuple?
【发布时间】:2017-06-04 17:02:27
【问题描述】:

ve got the newest ubuntu and I已经完成了:

sudo apt-get install postgresql postgresql-contrib
sudo apt-get install libpqxx-4.0v5
sudo apt-get install libpqxx-dev

我无法编译使用 pqxx::tuple 的程序。

编译:

g++ test.cpp -I/usr/local/include/ -lpqxx -lpq
or
g++ test.cpp -lpqxx -lpq -o test

控制台输出:

test.cpp: In function ‘int main()’:
test.cpp:15:21: error: ‘tuple’ in namespace ‘pqxx’ does not name a type
const pqxx::tuple row = r[rownum];

这是有问题的行:

const pqxx::tuple row = r[rownum];

当我删除这一行时,程序可以正常工作。

#include <iostream>
#include <pqxx/pqxx>
int main()
{
  try {
    pqxx::connection c("dbname=mydb user=postgres port=5432 password=*** hostaddr=127.0.0.1");
    pqxx::work w(c);
    pqxx::result r = w.exec("SELECT * FROM get_player_data_function()");
    w.commit();
    const int num_rows = r.size();
    for (int rownum=0; rownum < num_rows; ++rownum) {
        const pqxx::tuple row = r[rownum];
    }
  }
  catch (const std::exception &e) {
    std::cerr << e.what() << std::endl;
  }
}

【问题讨论】:

    标签: c++ postgresql c++11 linker libpqxx


    【解决方案1】:

    不确定...但如果我理解正确this page,您必须将pqxx::tuple 替换为pqxx::row

    所以,我想

    const pqxx::row row = r[rownum];
    

    【讨论】:

    • 更改后的输出:/tmp/ccEpNRjn.o: In function pqxx::result::operator[](unsigned long) const': test.cpp:(.text._ZNK4pqxx6resultixEm[_ZNK4pqxx6resultixEm]+0x27): undefined reference to pqxx::row::row(pqxx::result const*, unsigned long)' collect2: error: ld returned 1退出状态
    • @user3455638 - 前面的错误是编译错误;这是一个链接错误;所以我想你需要链接另一个库。但是,对不起,我不是pqxx的专家
    • 你说得对。首先,将 pqxx::tuple 更改为 pqxx::row。第二,链接器错误。使用 -L/usr/local/lib 和/或 -I/usr/local/include g++ test.cpp -I/usr/local/include -L/usr/local/lib -lpqxx -lpq 进行编译。 PQXXlib include 和 lib 位于 /usr/local/* 路径中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多