|
-
December 10th, 2002, 02:16 PM
#1
simple codes, cannot run in Solaris, need help
I have a very simple C++ program running fine at VC++ but having prob in compiling in Solaris using g++ .
Here are the complete codes.
Thanks in advance
#if !defined Utility_h
#define Utility_h
#include <string>
class Utility
{
public:
Utility();
virtual ~Utility();
static std::string dtoStr(double);
static std::string itoStr(int i);
static std::string out();
};
#endif // !defined Utility_h
#include "Utility.h"
#include <string>
#include <stdio.h>
using namespace std;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Utility::Utility()
{
}
Utility::~Utility()
{
}
string Utility: toStr(double d){
char strDouble[15];
//strDouble[14]='\0';
sprintf(strDouble,"%f",d);
//string s(strDouble);
return strDouble;
}
string Utility::itoStr(int i){
char strInt[15];
//strDouble[14]='\0'
sprintf(strInt,"%i",i);;
//itoa(i,strInt,10);
//sprintf(strDouble,"%f",d);
//string s(strDouble);
return strInt;
}
main.cxx
#include <iostream.h>
#include <string>
#include "Utility.h"
using namespace std;
int main(int argc, char **argv)
{
/*
double d=3.14;
char strDouble[15];
sprintf(strDouble,"%f",d);
*/
// cout << (T_STR) (Utility: toStr(3.14)).c_str() << endl;
string s=Utility: ut();
//string s=Utility::itoStr(1);
//cout <<s<<endl;
return 0;
} // main
-
December 10th, 2002, 02:33 PM
#2
What error do you get ?
It compiled OK for me using g++ on Linux.
It will not link correctly ... there is no code
for Utility::out()
-
December 10th, 2002, 02:48 PM
#3
Here is the part for out.
string Utility: ut(){
return "out test";
}
In fact, you can call other two methods. I was so sesperate so just putting something simple as returnning a string.
In Solaris, Utility.h and Utility.cpp and main.cpp are in the same folder, when call
g++ -o m.x main.cpp
get error
Undefined first referenced
symbol in file
Utility: ut(void) /var/tmp/ccyZGt5g.o
ld: fatal: Symbol referencing errors, No output written to m.x
collect2: ld returned 1 exit status
Very frustrated
-
December 10th, 2002, 02:59 PM
#4
You are not compiling the code in utility.cpp ...
g++ -o m.x main.cpp utility.cpp
-
December 10th, 2002, 03:02 PM
#5
after working on WIndows most of the time, I am dumb now .
Thank you very much for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|