iostream related link errors
I'm lost as to why the file shown at the bottom won't compile with CC (SunStudio 11), but it will with g++ (2.95.3). I get the following complaint when I build as noted (help!):
hicks@solar% CC foo.cc
Undefinedfirst referenced
symbolin file
char std::ios::widen(char)const foo.o
std::locale::~locale() foo.o
ld: fatal: Symbol referencing errors. No output written to a.out
//--
//--
#include <iostream>
#include <string.h>
int main(int argc, char* argv[])
{
char tstr[1024];
memset(tstr, 0, sizeof(tstr));
std::cout << "Enter a string, then press return: " ;
std::cin.getline(tstr, (sizeof(tstr)-1));
std::cout << std::endl << "You entered:" << std::endl << tstr << std::endl;
return 0;
}
[862 byte] By [
tahicks] at [2007-11-26 8:53:05]

# 2
The function std::locale::~locale() is in /usr/lib/libCstd.so.1. Each release of Sun Studio requires minimum patch levels on the C++ runtime libraries on each system that runs the compiler, and each system that runs programs created by the compiler.
Apparently you have an out-of-date version of the C++ runtime libraries. You can run the Sun Studio installer just to install the Solaris patches on your system, or you can download the latest C++ Runtime LIbrary patches here:
http://developers.sun.com/prodtech/cc/downloads/patches/index.jsp
There is no function std::ios::widen(char)const, so I don't understand where that reference is coming from. Could it be a copy-paste error? Various other "widen" functions are in /usr/lib/libCstd.so.1.
# 3
I did check for the copy past error and the undefined symbol complaint isaccurate. I did 2 additional things:
1.
% which CC
/opt/SUNWspro/bin/CC
2. commented out the line
std::cin.getline(tstr, (sizeof(tstr)-1));
with this line commented out compiling the file did not give any complaints and produced and executable. This std::ios::widen and std::locale::~locale() complaints appear to be related.
3 libCstd.so.1 is present (seems proper ...)
% ls -FaC /usr/lib/libCstd.so.1
/usr/lib/libCstd.so.1*
I'll look up that patch information next.
# 4
library /usr/lib/libCstd.so.1 is present on every Solaris installation. The question is whether the installed version is new enough.
I tried your example using the original release of Studio 11 compiled as you show:
CC foo.cc
It compiled and linked. So your problem is an out-of-date version of /usr/lib/libCstd.so.1. Instalingl the required C++ runtime library patch will fix it.
I solved the mystery of std::ios::widen. By default, all error messages run through the program c++filt, which simplifies the demangled names of standard library functions to make them look more like they way they appear in source code. For example when you reference std::string, it is really std::basic_string<char,std::char_traits><char>,std::allocator<ch ar> >. To make error messages more readable, c++filt simplies the type name back to std::string.
When you need to see the actual function names, you can use the option -filt=%none