problem with ar and C++ (?)

Discussion in 'C++' started by satya, Jan 29, 2007.

  1. satya

    satya Guest

    hi,
    I am using GNU g++ and GNU ar to create a C++ class library. I am
    facing the following problem:

    1.My class library has 3 classes say x,y,z organized in (x.h,x.cpp)
    (y.h,y.cpp) (z.h,z.cpp).
    2. Now I compiled all the classes using g++ -c x.cpp etc. obtaining
    x.o y.o and z.o
    3. I wrote a test file test.cpp using these classes.
    4. I compiled the test file like this: g++ x.o y.o z.o test.cpp --
    this was succesful -- produced an a.out
    5. Now I made a library: ar -cr libmyclass.a x.o y.o z.o
    6. g++ libmyclass.a test.cpp --> Undefined reference to x() !
    (constructor)
    7. I tried this too: g++ -L. -lmyclass test.cpp --> same error!

    Does anyone know why ?

    thanks!!
    satya.
    satya, Jan 29, 2007
    #1
    1. Advertising

  2. satya wrote:
    > I am using GNU g++ and GNU ar to create a C++ class library. I am
    > facing the following problem:
    >
    > 1.My class library has 3 classes say x,y,z organized in (x.h,x.cpp)
    > (y.h,y.cpp) (z.h,z.cpp).
    > 2. Now I compiled all the classes using g++ -c x.cpp etc. obtaining
    > x.o y.o and z.o
    > 3. I wrote a test file test.cpp using these classes.
    > 4. I compiled the test file like this: g++ x.o y.o z.o test.cpp --
    > this was succesful -- produced an a.out
    > 5. Now I made a library: ar -cr libmyclass.a x.o y.o z.o
    > 6. g++ libmyclass.a test.cpp --> Undefined reference to x() !
    > (constructor)
    > 7. I tried this too: g++ -L. -lmyclass test.cpp --> same error!
    >
    > Does anyone know why ?


    Yes, somebody in 'gnu.g++.help' knows. Here your g++-specific question
    is off-topic.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Jan 29, 2007
    #2
    1. Advertising

  3. satya

    Grizlyk Guest

    satya wrote:

    > 6. g++ libmyclass.a test.cpp --> Undefined reference to x() !


    switch objects
    g++ test.cpp libmyclass.a

    Linker serching library only for requested name, so first place "user"
    objects to declare externals, then library as "provider of requested
    externals".

    --
    Maksim A Polyanin
    Grizlyk, Jan 29, 2007
    #3
  4. satya

    Ron Natalie Guest

    satya wrote:

    > 6. g++ libmyclass.a test.cpp --> Undefined reference to x() !
    > (constructor)
    > 7. I tried this too: g++ -L. -lmyclass test.cpp --> same error!
    >
    > Does anyone know why ?
    >

    The order is important. Put test.cpp before the libraries.
    Ron Natalie, Jan 29, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric
    Replies:
    0
    Views:
    1,001
  2. Replies:
    1
    Views:
    2,342
  3. titi

    if and and vs if and,and

    titi, Mar 9, 2007, in forum: VHDL
    Replies:
    4
    Views:
    565
    Mike Treseler
    Mar 11, 2007
  4. John Walsch
    Replies:
    0
    Views:
    189
    John Walsch
    Jul 9, 2004
  5. Mike

    Problem problem problem :( Need Help

    Mike, May 7, 2004, in forum: ASP General
    Replies:
    2
    Views:
    528
    Bullschmidt
    May 11, 2004
Loading...

Share This Page