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;
}
}
輸出:/tmp/ccEpNRjn.o:在功能'pqxx ::結果::運算符[](無符號長)常量': TEST.CPP :(.text._ZNK4pqxx6resultixEm [_ZNK4pqxx6resultixEm] + 0x27):對pqxx :: row :: row(pqxx :: result const *,unsigned long)的未定義引用' collect2:錯誤:ld返回1退出狀態 – user3455638
@ user3455638 - 錯誤是編譯錯誤;這是一個鏈接錯誤;所以我想你需要鏈接另一個庫。但是,對不起,我不是'pqxx'專家' – max66
你是對的。首先,將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