compilation problem on linux

  • kvineeth

    kvineeth - 2008-05-19

    I am trying to compile the foll code on ubuntu linux:

    #include <pstreams.h>
    #include <pport.h>

    int main()
            const char* fname = "stmtest.txt";
            outfile f(fname,false);

            f.set_bufsize(1024);             // the default value in this version is 8192

                    f.put("This is a test file.");
            catch (estream* e)
                    perr.putf("File error: %s\n", e->get_message());
                    delete e;
            return 0;

    and on compilation i get the foll errors:

    g++ -Wall -g3 -c ex1.cpp -I/usr/include  -I../ptypes-2.1.1/include
    ex1.cpp: In function âint main()â:
    ex1.cpp:20: warning: cannot pass objects of non-POD type âclass pt::stringâ through â...â; call will abort at runtime
    g++ -g3 -o OBJ ex1.o  -L/usr/lib  -L../ptypes-2.1.1/so -L../ptypes-2.1.1/lib -pthread -lmysqlclient -lm
    ex1.o: In function `main':/home/users/PTYPES/examples/ex1.cpp:8: undefined reference to `pt::outfile::outfile(char const*, bool)'
    :/home/users/PTYPES/examples/ex1.cpp:10: undefined reference to `pt::iobase::set_bufsize(int)'
    :/home/users/PTYPES/examples/ex1.cpp:14: undefined reference to `pt::iobase::open()'
    :/home/users/PTYPES/examples/ex1.cpp:15: undefined reference to `pt::outstm::put(char const*)'
    :/home/users/PTYPES/examples/ex1.cpp:16: undefined reference to `pt::iobase::close()'
    :/home/users/PTYPES/examples/ex1.cpp:23: undefined reference to `pt::outfile::~outfile()'
    :/home/users/PTYPES/examples/ex1.cpp:23: undefined reference to `pt::outfile::~outfile()'
    ex1.o:(.gnu.linkonce.r._ZTIPN2pt7estreamE[typeinfo for pt::estream*]+0xc): undefined reference to `typeinfo for pt::estream'
    collect2: ld returned 1 exit status
    make: *** [OBJ] Error 1

    Could any one help me why i am getting these errors

    • spypunk

      spypunk - 2008-05-19

      Add -lptypes to the linker when you compile :

      g++ -g3 -o OBJ ex1.o -L/usr/lib -L../ptypes-2.1.1/so -L../ptypes-2.1.1/lib -pthread -lmysqlclient -lm -lptypes

    • Hovik Melikyan

      Hovik Melikyan - 2008-05-19

      A typecast to pconst (or const char*) fixes the problem:

      perr.putf("File error: %s\n", pconst(e->get_message()));

      This is new to GCC 4.x. Previously only Visual C was complaining about this type of typecasts.

      I'll fix the documentation, and thanks for pointing out.


    • Hovik Melikyan

      Hovik Melikyan - 2008-05-19

      And yes, the other errors are because you don't link the library, as spypunk wrote above.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks