I have a very very simple C++ file as follows that I'm compiling on Solaris 5-10 with the CC compiler. Here is the source code in my file myTest.C:
#include <map>
std::map<int, bool> myVar2;
I would like to first run the CC pre-processor on this file, examine the pre-processed file, and then compile that pre-processed file into an object file. I call this "indirect-compiling". To do this, I do the following:
% CC -P -o myFile_indirect.i myFile.C
% CC -c -o myFile_indirect.o myFile_indirect.i
I would also like to compile this file without a separate pre-processing step as is normally done. I call this "direct-compiling". To do this, I do the following:
% CC -c -o myFile_direct.o myFile.C
In theory, myFile_direct.o and myFile_indirect.o should be functionally equivalent. They should certainly contain the same number of symbols in their respective symbol tables right? So let's examine their symbols:
% gnm myFile_direct.o | c++filt > direct_symbols.txt
% gnm myFile_indirect.o | c++filt > indirect_symbols.txt
% wc -l *direct_symbols.txt
55 direct_symbols.txt
43 indirect_symbols.txt
Shockingly, the directly-compiled object file contains 12 symbols that are absent from the indirectly compiled file. Why? This seems like a serious bug to me. Why are these symbols absent from the indirectly compiled file? If they are unnecessary, why are they included in the directly compiled file? Isn't direct-compilation supposed to do the same pre-processing first and just hide it from the user? What is going on here?
PS. I don't recognize the twelve extra symbols nor do I understand what their purpose is:
00000010 T __rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rb_tree_node*__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__nil()
00000010 T __rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::iterator __rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::erase(__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::iterator)
00000010 T void __rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__erase(__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rb_tree_node*)
00000010 T __rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rb_tree_node*&__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__right(__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rb_tree_node*)
00000010 T __rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::iterator&__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::iterator::operator++()
00000010 T __rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rb_tree_node*__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__maximum(__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rb_tree_node*)
00000010 T __rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rb_tree_node*__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__minimum(__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rb_tree_node*)
00000010 T __rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rb_tree_node*&__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__leftmost()
00000010 T __rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rb_tree_node*&__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rightmost()
00000010 T void __rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__erase_leaf(__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rb_tree_node*)
00000010 T void __rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rotate_left(__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rb_tree_node*)
00000010 T void __rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rotate_right(__rwstd::__rb_tree<int,std::pair<const int,bool>,__rwstd::__select1st<std::pair<const int,bool>,int>,std::less<int>,std::allocator<std::pair<const int,bool> > >::__rb_tree_node*)
Try using CC -E
in place of CC -P
. When I do this thenm(1)
listings are the same and the object files only differ by a few bytes (given that I can see the names of the *.c
and *.i
files in the *.o
this difference is not surprising).
The man page doesn't really explain the difference between the two flags but does stress C++ for -E
so I wonder if -P
was intended to be C only.
If you're trying to work out what the direct method really entails, then this might prove enlightening:
truss -f -a -texec CC myFile.C
The direct compilation method doesn't call CC -P
or CC -E
but instead invokes ccfe
with a whole raft of flags (and then fbe
then ld
...).
来源:https://stackoverflow.com/questions/12870028/solaris-10-cc-preprocessor-bug-causes-undefined-symbols