| Title: | C++ | 
| Notice: | Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS) | 
| Moderator: | DECCXX::AMARTIN | 
| Created: | Fri Nov 06 1987 | 
| Last Modified: | Thu Jun 05 1997 | 
| Last Successful Update: | Fri Jun 06 1997 | 
| Number of topics: | 3604 | 
| Total number of notes: | 18242 | 
Why do I get an "undefined symbol" link-time error when "get_name" is
inline and the implementation of the member function is not in the H
file?  There is no error when the implementation is defined in the
class declaration and there is no error when the function is not
inline.
$cxx/version nl:
DEC C++ V5.4-010 on OpenVMS Alpha V6.1
$ cxx t
$cxx t1
$cxxlink t1,t
%LINK-W-NUDFSYMS, 1 undefined symbol:
%LINK-I-UDFSYM,         String Oper::get_name(void) const
%LINK-W-USEUNDEF, undefined symbol String Oper::get_name(void) const referenced
        in psect $LINK$ offset %X000000A0
        in module T1 file CIMENG11$:[EKD_V010.WRK.KLEE.SRC]T1.OBJ;5
Thanks,
Kamyee (and Bill too)
=========================
// t.h
#if !defined T_H
#define T_H 
#include <string.hxx>
class Oper
{
private:
  String name;
public:
  Oper ( void );	// constructor
  String get_name( void ) const;
};
#endif                                  /* T_H */
===================================
// t.cxx
#include <iostream.hxx>
#include <t.h>
Oper::Oper( void) { this->name = "Blah"; }
inline             // THIS KEYWORD CAUSES UNDEFINED SYMBOL
String Oper::get_name ( void ) const {return this->name;}
==================================
//t1.cxx
#include <iostream.hxx>
#include <t.h>
main( void )
{
  Oper aOper;
  cout << aOper.get_name() << endl;
}
| T.R | Title | User | Personal Name | Date | Lines | 
|---|---|---|---|---|---|
| 3467.1 | SPECXN::DERAMO | Dan D'Eramo | Wed Feb 26 1997 11:10 | 27 | |
|         File T1.OBJ has a reference to the externally defined
        "String Oper::get_name(void) const".  So at link time,
        there must be a definition of that available.
        
        T1.OBJ has no such definition because there is none in
        the source.
        
        T.OBJ has no such definition, I believe because under
        ARM rules the "inline" keyword means the definition there
        has internal linkage.
        It would be as if you had done the following in C/C++
        
        /* T1 */
        	extern void f(void);
        	int main() { f(); return 0; }
        
        /* T */
        	static void f(void) {}
        
        The definition of f in T has internal linkage and so at link
        time does not satify T1's need for a definition of f.
        
        I think the latest draft of the evolving standard changes that
        ARM rule about inline and internal linkage.
        
        Dan
 | |||||