CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2002
    Posts
    42

    Unhappy 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

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725
    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()

  3. #3
    Join Date
    Oct 2002
    Posts
    42
    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

  4. #4
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725
    You are not compiling the code in utility.cpp ...

    g++ -o m.x main.cpp utility.cpp

  5. #5
    Join Date
    Oct 2002
    Posts
    42
    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
  •  





Click Here to Expand Forum to Full Width

Featured