ar loses std::list symbols

S

Shea Martin

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.
 
X

Xenos

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.
 
S

Shea Martin

Xenos said:
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.

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top