Article View: gnu.g++.help
Article #705Problem linking with g++ class
From: keith
Date: Tue, 26 Jan 1993 14:54
Date: Tue, 26 Jan 1993 14:54
133 lines
2725 bytes
2725 bytes
I am having difficulties linking to a very simple class with g++.
The program compiles, links and runs properly with BC++ 3.1.
I am running gcc 2.3.3
with libg++ 2.3 on a SUN OS 4.1.1. Gcc is installed in a directory
other than /usr/local.
I have tried to make the class as simple as possible and based its
design on Complex.h in libg++. I have tried a similiar test program
with the Complex.h class and it compiled, linked and ran properly with
g++. The 2 test files and the class I am trying to link to are
included at the end of this file.
When I type the command
g++ test1.c test2.c -lm
I get the error message
ld: Undefined symbol
___7mpfloatRC7mpfloat
___7mpfloatd
___ml__FRC7mpfloatT0
__$_7mpfloat
collect: /usr/bin/ld returned 2 exit status
I am obviously missing something simple. Could someone please point
it out to me.
Thanks in advance.
Keith S Cover
Physics, UBC
keith@msmri.med.ubc.ca
test1.c
=======
#include <iostream.h>
#include <math.h>
#include "mpf14.h"
mpfloat square(mpfloat a);
main() {
mpfloat a = 4;
mpfloat b = square(a);
return 0;
}
test2.c
=======
#include "mpf14.h"
mpfloat square(mpfloat a) {
return( a*a );
}
mpf14.h
=======
#ifndef _mpfloat_h
#ifdef __GNUG__
#pragma interface
#endif
#define _mpfloat_h 1
// INCLUDE FILES
#include <iostream.h>
#include <math.h>
#include <stdlib.h>
class mpfloat {
protected:
double num;
public:
// constructors and destructors
mpfloat();
mpfloat(const mpfloat& x);
mpfloat(const double x);
~mpfloat();
// get value
double getnum() const;
};
// INLINE FUNCTION PROTOTYPES
// Arithmetic operators
mpfloat operator * ( const mpfloat& x, const mpfloat& y);
// INLINE MEMBERS
// constructors
inline mpfloat::mpfloat() {
}
inline mpfloat::mpfloat(const mpfloat& x) :num(x.getnum()) {
}
inline mpfloat::mpfloat(const double x) {
num = x;
}
inline mpfloat::~mpfloat() {
}
// Get number
inline double mpfloat::getnum() const {
return(num);
}
// Inline Functions
inline mpfloat operator * ( const mpfloat& x, const mpfloat& y) {
return mpfloat( x.getnum()*y.getnum() );
}
#endif // _mpfloat_h
Technical Details
Message-ID:
<1k3jc2INNjnk@iskut.ucs.ubc.ca>Path:
arc1-ca.pugleaf.net!sparky!uunet!dtix!darwin.sura.net!gatech!destroyer!cs.ubc.ca!unixg.ubc.ca!keithShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!dtix!darwin.sura.net!gatech!destroyer!cs.ubc.ca!unixg.ubc.ca!keith From: keith@msmri.med.ubc.ca Newsgroups: gnu.g++.help Subject: Problem linking with g++ class Message-ID: <1k3jc2INNjnk@iskut.ucs.ubc.ca> Date: 26 Jan 93 14:54:58 GMT Organization: University of British Columbia, Vancouver, B.C., Canada Lines: 133 NNTP-Posting-Host: msmri.med.ubc.ca