ar loses std::list symbols

Discussion in 'C++' started by Shea Martin, Dec 1, 2003.

  1. Shea Martin

    Shea Martin Guest

    Solaris 9, Sun Workshop 5.0

    I have ObjectA.o, ObjectB.o. ObjectA.o uses std::list.
    I created a archive of the objects: ar cvr libAB.a *.o.

    I have example.cc which I am trying to compile against ObjectA ObjectB.

    1. CC -I. -o example.bin example.cc ./libAB.a
    this fails, on link error to std::list.

    2. CC -I. -o example.bin example.cc ObjectA.o ObjectB.o
    this works.

    Anyone know why method 2 works, and not method 1? I really need those
    objects in the archive.

    Thanks.

    ~Shea M.

    ps - Not sure if this matters or not (other than the fact it is poor
    design, but ObjectA and ObjectB reference one another.
     
    Shea Martin, Dec 1, 2003
    #1
    1. Advertisements

  2. Shea Martin

    Xenos Guest

    Don't use CC, use CXX (or whatever define is set for you c++ compiler). CC
    if defined as a C compiler (i.e., gcc) won't link in the standard C++
    library. So, for example, use g++ instead of gcc. I use STL and archives
    all the time, and never had this problem.


    "Shea Martin" <> wrote in message
    news:eek:AKyb.16107$f7.769938@localhost...
    > Solaris 9, Sun Workshop 5.0
    >
    > I have ObjectA.o, ObjectB.o. ObjectA.o uses std::list.
    > I created a archive of the objects: ar cvr libAB.a *.o.
    >
    > I have example.cc which I am trying to compile against ObjectA ObjectB.
    >
    > 1. CC -I. -o example.bin example.cc ./libAB.a
    > this fails, on link error to std::list.
    >
    > 2. CC -I. -o example.bin example.cc ObjectA.o ObjectB.o
    > this works.
    >
    > Anyone know why method 2 works, and not method 1? I really need those
    > objects in the archive.
    >
    > Thanks.
    >
    > ~Shea M.
    >
    > ps - Not sure if this matters or not (other than the fact it is poor
    > design, but ObjectA and ObjectB reference one another.
    >
     
    Xenos, Dec 1, 2003
    #2
    1. Advertisements

  3. Shea Martin

    Shea Martin Guest

    Xenos wrote:
    > Don't use CC, use CXX (or whatever define is set for you c++ compiler). CC
    > if defined as a C compiler (i.e., gcc) won't link in the standard C++
    > library. So, for example, use g++ instead of gcc. I use STL and archives
    > all the time, and never had this problem.


    The Sun Workshop Compilers are CC: for C++, cc: for c. Just a different
    naming scheme from the GNU compilers.

    >>Solaris 9, Sun Workshop 5.0
    >>
    >>I have ObjectA.o, ObjectB.o. ObjectA.o uses std::list.
    >>I created a archive of the objects: ar cvr libAB.a *.o.
    >>
    >>I have example.cc which I am trying to compile against ObjectA ObjectB.
    >>
    >>1. CC -I. -o example.bin example.cc ./libAB.a
    >>this fails, on link error to std::list.
    >>
    >>2. CC -I. -o example.bin example.cc ObjectA.o ObjectB.o
    >>this works.
    >>
    >>Anyone know why method 2 works, and not method 1? I really need those
    >>objects in the archive.


    Solved:
    If anyone is familiar with workshop, then you know that CC generates
    SunWS_Cache directories whenever you compile code which uses templates.
    Using -pto flag will turn off the creation of this cache directory. I
    have always used this flag, b/c I find the directory annoying.

    Well I re read Sun's docs on CC, and if you carefully between the lines,
    it is inferred that this cache is needed for creating static
    archives/libs when the objects use templates.

    Removing the -pto flag and recompiling fixes everything. Once the lib
    has been created the cache can be removed, and you will still be able to
    link to the library.

    Hope this one helps someone else in the future, as I wasted a LOT of
    time on it!!!

    Here are some keywords for people using groups.google.com:
    templates undefined symbol std template list -pto Sun Workshop
    SunWS_Cache lib *.a *.o static archive ar -xar Makefile CC

    Later,

    ~S
     
    Shea Martin, Dec 1, 2003
    #3
    1. Advertisements

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. Peter Jansson
    Replies:
    5
    Views:
    6,968
    Ivan Vecerina
    Mar 17, 2005
  2. Vinu
    Replies:
    4
    Views:
    538
    Jim Langston
    Jul 7, 2005
  3. Vinu
    Replies:
    0
    Views:
    488
  4. Replies:
    6
    Views:
    943
    Jim Langston
    Oct 30, 2005
  5. Geoffrey S. Knauth
    Replies:
    6
    Views:
    1,292
    Earl Purple
    Jan 18, 2006
  6. puzzlecracker
    Replies:
    3
    Views:
    2,277
    Mike Wahler
    May 8, 2006
  7. Jeffrey Walton
    Replies:
    10
    Views:
    1,252
    Mathias Gaunard
    Nov 26, 2006
  8. Juha Nieminen
    Replies:
    22
    Views:
    1,335
    Kai-Uwe Bux
    Oct 12, 2007
Loading...