Send in your Unix questions today! |
See additional Unix tips and tricks

I recently decided that it was time that I learn a little C+
+. After all, I studied Computer Science back when Unix was a toddler and now have a daughter who is taking Math and Computer Science classes at UCLA. So, I started with a typical "hello, world" kind of program and tried to compile it on my newly installed Solaris 10 system. But, instead of an easy compilation of my embarrassingly simple program, I ran into a series of errors:
boson> c++ easy.c
In file included from /usr/include/sys/wait.h:24,
from /usr/include/stdlib.h:22,
from /usr/local/include/c++/3.3.2/cstdlib:52,
from /usr/local/include/c++/3.3.2/bits/stl_algobase.h:67,
from /usr/local/include/c++/3.3.2/memory:54,
from /usr/local/include/c++/3.3.2/string:48,
from /usr/local/include/c++/3.3.2/bits/locale_classes.h:47,
from /usr/local/include/c++/3.3.2/bits/ios_base.h:47,
from /usr/local/include/c++/3.3.2/ios:49,
from /usr/local/include/c++/3.3.2/ostream:45,
from /usr/local/include/c++/3.3.2/iostream:45,
from easy.c:1:
/usr/include/sys/siginfo.h:259: error: 'ctid_t' is used as a type, but is not
defined as a type.
/usr/include/sys/siginfo.h:390: error: 'ctid_t' is used as a type, but is not
defined as a type.
|
"What is wrong with my signinfo.h file?" I wondered, looking at the traceback. And, since the system will soon be replacing a development system, I couldn't help but imagine my inability to compile the simplest possible program was a bad omen for the box when it was turned over to people who program fifty hours a week.
The program, as you'll see from the text below, has only one significant line of code -- the equivalent of a printf statement. How this modest program engendered an error in a signal header file was beyond my grasp.
#include <iostream>
int main()
{
std::cout << "Welcome to the wonderful world of C++!!!\n";
return 0;
}
|
After some googling, I determined that the problem that I was experiencing related to a conflict between my Solaris 10 and gcc package's header files. Fortunately, I also discovered that I could rebuild gcc's 'adapted' headers by running a script already available on my system. When I ran a find, I found two versions, very similar but not identical.
bash-3.00# find /usr -name mkheaders -print
/usr/sfw/libexec/gcc/sparc-sun-solaris2.10/3.4.3/install-tools/mkheaders
/usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/install-tools/mkheaders
boson> /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/install-tools/mkheaders
fixproto: populating `/usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/include'
(No *.h files in /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/include/evolution-1.4)
(No *.h files in /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/include/root)
(No *.h files in /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/include/root/usr)
(No *.h files in /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/include/root/usr/openwin)
(No *.h files in /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/include/root/usr/openwin/share)
(No *.h files in /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/include/root/usr/openwin/share/include)
(No *.h files in /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/include/root/usr/openwin/share/include/X11)
(No *.h files in /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/include/X11)
|
I was then able to compile my program without problems.
make easy
c++ -o easy easy.c
|
When I tried to run the program, however, I ran into a problem. The loader couldn't find a needed library -- libstdc++.so.5:
bash-3.00# ./easy
ld.so.1: easy: fatal: libstdc++.so.5: open failed: No such file or directory
Killed
|
Searching, I found several libraries by that name:
# find /usr -name "libstdc++.so.5" -print
/usr/lib/AdobeReader/Reader/sparcsolaris/lib/libstdc++.so.5
/usr/local/lib/libstdc++.so.5
/usr/local/lib/sparcv9/libstdc++.so.5
|
To verify that my program would run properly with the previously "missing" library, I added two of the paths to my LD_LIBRARY_PATH variable:
export LD_LIBRARY_PATH:/usr/local/lib:/usr/sfw/lib
|
At this point, my program ran properly.
boson> ./easy
Welcome to the wonderful world of C++!!!
|
Using the crle (configure runtime linking environment) command, I verified that neither of these paths was configured as a system-wide default:
boson> crle
Default configuration file (/var/ld/ld.config) not found
Default Library Path (ELF): /lib:/usr/lib (system default)
Trusted Directories (ELF): /lib/secure:/usr/lib/secure (system default)
|
I then used the crle command (very cautiously!) and added the new paths. With this change, I will not need to configure the LD_LIBRARY_PATH variable for the users on this system.
# crle -l /lib:/usr/lib:/usr/local/lib:/usr/local/lib/sparcv9
|
I then ran crle again to confirm the change:
# crle
Configuration file [version 4]: /var/ld/ld.config
Default Library Path (ELF): /lib:/usr/lib:/usr/local/lib:/usr/local/lib/sparcv9
Trusted Directories (ELF): /lib/secure:/usr/lib/secure (system default)
Command line:
crle -c /var/ld/ld.config -l /lib:/usr/lib:/usr/local/lib:/usr/local/lib/sparcv9
|
Running crle also created a /var/ld/ld.config file on my system to retain the modified library path through system reboots.
# more /var/ld/ld.config
X/lib:/usr/lib:/usr/local/lib:/usr/local/lib/sparcv9
|
To be triple sure that the system was doing everything as it should, I unset my LD_LIBRARY_PATH variable and ran my simple program again.
unset LD_LIBRARY_PATH
./easy
Welcome to the wonderful world of C++!!!
|