From http://linux.die.net/man/1/ld :
- wrap = symbol
Use the wrapper function for the character. Any undefined reference to a symbol will be resolved to "_wrap symbol". Any undefined reference to "_real symbol" will be resolved to the symbol.
I think the word "undefined" may be the key here. Your character of interest is definitely defined in bar.o, and the nm output confirms it, because undefined characters are marked with a "U", not a "W".
Update:
I think it's therefore not possible to wrap template functions?
I think it depends more on where the function is defined (or created), and if that definition is available to the linker. In your case, if you defined a function without a template in bar.cpp where it is used, the result will be the same. Even if you defined the function in bar.cpp, but used it in main.cpp, I think it will be the same, although not entirely sure (you can try). And I'm sure that if you linked bar.cpp and main.cpp with different modules (shared library and executable), then you can wrap the function from bar.cpp used in main.cpp, again, regardless of whether the template is or not .
Update 2: I was not sure, but Mike confirmed the experiment (see his own answer and comments there) that the wrapper works if the character is undefined in the object file, even if this object file is linked with another object file containing the definition of the character. Excellent!
source share