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

  1. Newsgroups: gnu.g++.help
  2. Path: sparky!uunet!stanford.edu!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!torn!newshost.uwo.ca!lab1.apmaths.uwo.ca!honglin
  3. From: honglin@apmaths.uwo.ca (HONGLIN YE)
  4. Subject: Re: Problem linking with g++ class
  5. Organization: Applied Mathematics, U.W.O
  6. Date: Tue, 26 Jan 1993 19:32:12 GMT
  7. Message-ID: <honglin.18@apmaths.uwo.ca>
  8. References: <1k3jc2INNjnk@iskut.ucs.ubc.ca>
  9. Sender: news@julian.uwo.ca (USENET News System)
  10. Nntp-Posting-Host: lab1.apmaths.uwo.ca
  11. Lines: 154
  12.  
  13.    
  14.   Hi,
  15.  
  16.      I don't think you can get an answer from this news group for that 
  17.  
  18.   problen. There have been many help requests on that matter in the group,
  19.  
  20.   but people simply ignored or maybe they don't know the answer yet.
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. In article <1k3jc2INNjnk@iskut.ucs.ubc.ca> keith@msmri.med.ubc.ca writes:
  29.  
  30.  
  31. >I am having difficulties linking to a very simple class with g++.
  32. >The program compiles, links and runs properly with BC++ 3.1.  
  33. >I am running gcc 2.3.3 
  34. >with libg++ 2.3 on a SUN OS 4.1.1.  Gcc is installed in a directory
  35. >other than /usr/local. 
  36.  
  37. >I have tried to make the class as simple as possible and based its 
  38. >design on Complex.h in libg++.  I have tried a similiar test program
  39. >with the Complex.h class and it compiled, linked and ran properly with
  40. >g++.  The 2 test files and the class I am trying to link to are 
  41. >included at the end of this file.
  42.  
  43. >When I type the command
  44.  
  45. >    g++ test1.c test2.c -lm
  46.  
  47. >I get the error message
  48.  
  49. >    ld: Undefined symbol 
  50. >       ___7mpfloatRC7mpfloat 
  51. >       ___7mpfloatd 
  52. >       ___ml__FRC7mpfloatT0 
  53. >       __$_7mpfloat 
  54. >    collect: /usr/bin/ld returned 2 exit status
  55.  
  56. >I am obviously missing something simple.  Could someone please point
  57. >it out to me.
  58.  
  59. >Thanks in advance.
  60.  
  61. >Keith S Cover
  62. >Physics, UBC
  63. >keith@msmri.med.ubc.ca
  64.  
  65. >test1.c
  66. >=======
  67.  
  68. >#include <iostream.h>
  69. >#include <math.h>
  70. >#include "mpf14.h"
  71.  
  72. >mpfloat square(mpfloat a);
  73.  
  74. >main() {
  75.  
  76. >    mpfloat a = 4;
  77. >    mpfloat b = square(a);
  78.  
  79. >    return 0;
  80. >}
  81.  
  82.  
  83. >test2.c
  84. >=======
  85.  
  86. >#include "mpf14.h"
  87.  
  88. >mpfloat square(mpfloat a) {
  89.  
  90. >    return( a*a );
  91.  
  92. >}
  93.  
  94.  
  95. >mpf14.h
  96. >=======
  97.  
  98. >#ifndef _mpfloat_h
  99. >#ifdef __GNUG__
  100. >#pragma interface
  101. >#endif
  102. >#define _mpfloat_h 1
  103.  
  104.  
  105. >// INCLUDE FILES 
  106. >#include <iostream.h>
  107. >#include <math.h>
  108. >#include <stdlib.h>
  109.  
  110.  
  111. >class mpfloat {
  112.  
  113. >protected:
  114.  
  115. >    double num;
  116.  
  117. >public:
  118.  
  119. >    // constructors and destructors
  120. >    mpfloat();
  121. >    mpfloat(const mpfloat& x);
  122. >    mpfloat(const double x);
  123. >    ~mpfloat();
  124.  
  125. >    // get value
  126. >    double getnum() const;
  127.  
  128. >};
  129.  
  130.  
  131. >// INLINE FUNCTION PROTOTYPES
  132.  
  133. >// Arithmetic operators
  134. >mpfloat operator * ( const mpfloat& x, const mpfloat& y);
  135.  
  136. >// INLINE MEMBERS
  137.  
  138. >// constructors
  139. >inline mpfloat::mpfloat() {
  140. >}
  141. >inline mpfloat::mpfloat(const mpfloat& x) :num(x.getnum()) {
  142. >}
  143. >inline mpfloat::mpfloat(const double x) {
  144. >    num = x;
  145. >}
  146. >inline mpfloat::~mpfloat() {
  147. >}
  148.  
  149.  
  150. >// Get number
  151. >inline double mpfloat::getnum() const {
  152. >    return(num);
  153. >}
  154.  
  155.  
  156. >// Inline Functions
  157.  
  158. >inline mpfloat operator * ( const mpfloat& x, const mpfloat& y) {
  159. >    return mpfloat( x.getnum()*y.getnum() );
  160. >}
  161.  
  162. >#endif // _mpfloat_h
  163.  
  164.  
  165.  
  166.  
  167.