2017-06-04 66 views
0

ve got the newest ubuntu and I已经做了:libpqxx库中没有pqxx :: tuple?

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

我不能老是编译程序,其采用pqxx ::元组。

编译:

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

回答

1

不知道......但如果我理解正确的话this page,你需要替换pqxx::tuplepqxx::row

所以,我想改变之后

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

输出:/tmp/ccEpNRjn.o:在功能'pqxx ::结果::运算符[](无符号长)常量': TEST.CPP :(.text._ZNK4pqxx6resultixEm [_ZNK4pqxx6resultixEm] + 0x27):对pqxx :: row :: row(pqxx :: result const *,unsigned long)的未定义引用' collect2:错误:ld返回1退出状态 – user3455638

+1

@ user3455638 - 错误是编译错误;这是一个链接错误;所以我想你需要链接另一个库。但是,对不起,我不是'pqxx'专家' – max66

+0

你是对的。首先,将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/*路径中。 – user3455638