By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,169 Members | 1,059 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,169 IT Pros & Developers. It's quick & easy.

ar loses std::list symbols

P: n/a
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.

Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <sm*****@arcis.com> wrote in message
news:oAKyb.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.

Jul 22 '05 #2

P: n/a
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

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.