[ Mr. Rejn @ 01.06.2009. 19:31 ] @
Pokusavam da ugradim kod Postgres pqxx biblioteke u C++ program.
g++ javlja ovu gresku pri sastavljanju:
Code:

In file included from /usr/include/pqxx/connection_base:22,
                 from /usr/include/pqxx/basic_connection.hxx:24,
                 from /usr/include/pqxx/basic_connection:22,
                 from /usr/include/pqxx/connection.hxx:23,
                 from /usr/include/pqxx/connection:22,
                 from /usr/include/pqxx/pqxx:18,
                 from MainWindow.CPP:82:
/usr/include/pqxx/connection_base.hxx:669: error: expected unqualified-id before ‘)’ token
In file included from /usr/include/pqxx/transaction_base:23,
                 from /usr/include/pqxx/cursor.hxx:27,
                 from /usr/include/pqxx/cursor:22,
                 from /usr/include/pqxx/pqxx:19,
                 from MainWindow.CPP:82:
/usr/include/pqxx/transaction_base.hxx:308: error: expected identifier before ‘int’
/usr/include/pqxx/transaction_base.hxx:309: error: expected unqualified-id before ‘{’ token



Medjutim deo koda koji sam stavio u moj program se uredno sastavlja kad je izolovan u main():
Code:

#include <iostream>
#include "pqxx/pqxx"

    using namespace std;
    using namespace pqxx;

    int main()
    {
        try
        {
            connection C("host=localhost port=5432 dbname=pagilla user=postgres password=postgres");
            cout << "Connected to " << C.dbname() << endl;
            work W(C);

            result R = W.exec("SELECT * FROM actor");

            cout << "Nashao " << R.size() << "glumaca:" << endl;
            for (result::const_iterator r = R.begin();
                 r != R.end();
                 ++r)
            {
                 cout << r[0].c_str() <<' '<<r[1].c_str()<<' '<<r[2].c_str()<<' '<<r[3].c_str() << endl;
            }
        }
        catch (const exception &e)
        {
            cerr << e.what() << endl;
            return 1;
        }
        return 0;
    }

Mozda neko zna o cemu se radi? (moj C++ nivo je pocetnicki)
[ Mihajlo Cvetanović @ 01.06.2009. 23:28 ] @
Pa da bismo našli grešku obično je korisnije da vidimo kod koji proizvodi grešku, nego kod u kome je sve u redu. Pretpostavljam da je problem u tome što postgres koristi neki token/promenljivu/makro, a taj token je prethodno definisan u Windows SDK, ili u MFC, ili gde već. Token nije definisan u izolovanom main primeru. Moguće rešenje je da staviš #include "pqxx/pqxx" pre bilo kog drugog #include, makar morao u stdafx.h da ga staviš (ako radiš s MFC-om).

BTW, nemam veze s postgresom, moraćeš da daš više podataka ako te odgovor ne zadovoljava. Šta je u linijama connection_base:22, transaction_base:23 i transaction_base.hxx:308? Dodaj i malo okolnog koda.
[ karas @ 02.06.2009. 08:33 ] @
Kako kompajliras, da li si ukljucio biblioteku? Daj celu komandu kojom pozivas g++ (ako radis pod Linuksom).
[ Mr. Rejn @ 02.06.2009. 10:33 ] @
Citat:
Mihajlo Cvetanović: Moguće rešenje je da staviš #include "pqxx/pqxx" pre bilo kog drugog #include

Dabome, da se stavi ispred ostalih #include-a. Samo to nisam probao:) Sad radi.

[Ovu poruku je menjao Mr. Rejn dana 02.06.2009. u 12:30 GMT+1]