0

CentOS 6.3 で libpqxx ライブラリを使用して、データベースから複数の行を選択する単純なコードをコンパイルしようとしています。

#include <pqxx/pqxx>

using namespace std;
using namespace pqxx;

int main(int argc, char* argv[])
{
    char * sql;

    try{
        connection C("dbname=testdb user=postgres password=cohondob \
        hostaddr=127.0.0.1 port=5432");
        if (C.is_open()) {
            cout << "Opened database successfully: " << C.dbname() << endl;
        } else {
            cout << "Can't open database" << endl;
            return 1;
        }
        /* Create SQL statement */
        sql = "SELECT * from COMPANY";

        /* Create a non-transactional object. */
        nontransaction N(C);

        /* Execute SQL query */
        result R( N.exec( sql ));

        /* List down all the records */
        for (result::const_iterator c = R.begin(); c != R.end(); ++c) {
            cout << "ID = " << c[0].as<int>() << endl;
            cout << "Name = " << c[1].as<string>() << endl;
            cout << "Age = " << c[2].as<int>() << endl;
            cout << "Address = " << c[3].as<string>() << endl;
            cout << "Salary = " << c[4].as<float>() << endl;
        }
        cout << "Operation done successfully" << endl;
        C.disconnect ();
    }catch (const std::exception &e){
        cerr << e.what() << std::endl;
        return 1;
    }

    return 0;
}

次のリンカ エラーが発生します。

ASP:/root/test/libpqxx_folder$ g++ -g libpqxx_select_from_table.cpp -L/usr/lib64 -lpqxx -lpq -o select libpqxx_select_from_table.cpp: 関数 'int main(int, char**)': libpqxx_select_from_table.cpp: 21: 警告: 文字列定数から 'char*' への非推奨の変換 /tmp/cc0bFRAY.o: 関数main': /root/test/libpqxx_folder/libpqxx_select_from_table.cpp:30: undefined reference topqxx::result::begin() 内 const' /root/test/libpqxx_folder/libpqxx_select_from_table.cpp:31: への未定義の参照pqxx::tuple::operator[](int) const' /root/test/libpqxx_folder/libpqxx_select_from_table.cpp:32: undefined reference topqxx::tuple::operator const' /root/test/libpqxx_folder/libpqxx_select_from_table.cpp:33: pqxx::tuple::operator[](int) const' /root/test/libpqxx_folder/libpqxx_select_from_table.cpp:34: undefined reference topqxx::tuple::operator const' /root/test/libpqxx_folder/libpqxx_select_from_table.cpp:35 への未定義参照pqxx::tuple::operator[](int) const' /tmp/cc0bFRAY.o: In functionbool pqxx::field::to, std::allocator > >(std::basic_string, std::allocator >&) const': /usr/local/include/pqxx/field.hxx:190: pqxx::field::c_str() const' /usr/local/include/pqxx/field.hxx:191: undefined reference topqxxへの未定義参照::field::is_null() const' /usr/local/include/pqxx/field.hxx:192: pqxx::field::size() const' /tmp/cc0bFRAY.o: In functionconst_result_iterator への未定義参照': /usr/local/include/pqxx/result.hxx:334: pqxx::tuple::tuple(pqxx::result const*, unsigned long)' /tmp/cc0bFRAY.o: In functionboolへの未定義参照pqxx::field::to(int&) const': /usr/local/include/pqxx/field.hxx:119: pqxx::field::c_str() const' /usr/local/include/pqxx/field.hxx:120: undefined reference topqxx::field::is_null() への未定義参照 const' /tmp/cc0bFRAY.o: In function bool pqxx::field::to<float>(float&) const': /usr/local/include/pqxx/field.hxx:119: undefined reference topqxx::field::c_str() const' /usr/local/include/pqxx/field.hxx:120: `pqxx::field::is_null() const' collect2 への未定義の参照: ld は 1 つの終了ステータスを返しました

よろしくお願いします。

4

0 に答える 0