home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / g / help / 1707 < prev    next >
Encoding:
Text File  |  1993-01-27  |  2.5 KB  |  144 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!gatech!destroyer!cs.ubc.ca!unixg.ubc.ca!keith
  2. From: keith@msmri.med.ubc.ca
  3. Newsgroups: gnu.g++.help
  4. Subject: Problem linking with g++ class
  5. Message-ID: <1k3jc2INNjnk@iskut.ucs.ubc.ca>
  6. Date: 26 Jan 93 14:54:58 GMT
  7. Organization: University of British Columbia, Vancouver, B.C., Canada
  8. Lines: 133
  9. NNTP-Posting-Host: msmri.med.ubc.ca
  10.  
  11.  
  12. I am having difficulties linking to a very simple class with g++.
  13. The program compiles, links and runs properly with BC++ 3.1.  
  14. I am running gcc 2.3.3 
  15. with libg++ 2.3 on a SUN OS 4.1.1.  Gcc is installed in a directory
  16. other than /usr/local. 
  17.  
  18. I have tried to make the class as simple as possible and based its 
  19. design on Complex.h in libg++.  I have tried a similiar test program
  20. with the Complex.h class and it compiled, linked and ran properly with
  21. g++.  The 2 test files and the class I am trying to link to are 
  22. included at the end of this file.
  23.  
  24. When I type the command
  25.  
  26.     g++ test1.c test2.c -lm
  27.  
  28. I get the error message
  29.  
  30.     ld: Undefined symbol 
  31.        ___7mpfloatRC7mpfloat 
  32.        ___7mpfloatd 
  33.        ___ml__FRC7mpfloatT0 
  34.        __$_7mpfloat 
  35.     collect: /usr/bin/ld returned 2 exit status
  36.  
  37. I am obviously missing something simple.  Could someone please point
  38. it out to me.
  39.  
  40. Thanks in advance.
  41.  
  42. Keith S Cover
  43. Physics, UBC
  44. keith@msmri.med.ubc.ca
  45.  
  46. test1.c
  47. =======
  48.  
  49. #include <iostream.h>
  50. #include <math.h>
  51. #include "mpf14.h"
  52.  
  53. mpfloat square(mpfloat a);
  54.  
  55. main() {
  56.  
  57.     mpfloat a = 4;
  58.     mpfloat b = square(a);
  59.  
  60.     return 0;
  61. }
  62.  
  63.  
  64. test2.c
  65. =======
  66.  
  67. #include "mpf14.h"
  68.  
  69. mpfloat square(mpfloat a) {
  70.  
  71.     return( a*a );
  72.  
  73. }
  74.  
  75.  
  76. mpf14.h
  77. =======
  78.  
  79. #ifndef _mpfloat_h
  80. #ifdef __GNUG__
  81. #pragma interface
  82. #endif
  83. #define _mpfloat_h 1
  84.  
  85.  
  86. // INCLUDE FILES 
  87. #include <iostream.h>
  88. #include <math.h>
  89. #include <stdlib.h>
  90.  
  91.  
  92. class mpfloat {
  93.  
  94. protected:
  95.  
  96.     double num;
  97.  
  98. public:
  99.  
  100.     // constructors and destructors
  101.     mpfloat();
  102.     mpfloat(const mpfloat& x);
  103.     mpfloat(const double x);
  104.     ~mpfloat();
  105.  
  106.     // get value
  107.     double getnum() const;
  108.  
  109. };
  110.  
  111.  
  112. // INLINE FUNCTION PROTOTYPES
  113.  
  114. // Arithmetic operators
  115. mpfloat operator * ( const mpfloat& x, const mpfloat& y);
  116.  
  117. // INLINE MEMBERS
  118.  
  119. // constructors
  120. inline mpfloat::mpfloat() {
  121. }
  122. inline mpfloat::mpfloat(const mpfloat& x) :num(x.getnum()) {
  123. }
  124. inline mpfloat::mpfloat(const double x) {
  125.     num = x;
  126. }
  127. inline mpfloat::~mpfloat() {
  128. }
  129.  
  130.  
  131. // Get number
  132. inline double mpfloat::getnum() const {
  133.     return(num);
  134. }
  135.  
  136.  
  137. // Inline Functions
  138.  
  139. inline mpfloat operator * ( const mpfloat& x, const mpfloat& y) {
  140.     return mpfloat( x.getnum()*y.getnum() );
  141. }
  142.  
  143. #endif // _mpfloat_h
  144.