Problems with ld: Unresolved error C++ compiling error

Discussion in 'C++' started by stevenruiz@gmail.com, Feb 13, 2007.

  1. Guest

    Hi Everyone,

    > The problem that I have involves program that searches for a certain string within a file. As seen in the code, I have declared a Strings class which overrides the string class in C++. Inside of this class, it has a function called findStr (replaces the find in string.h) which will return a 0 when it is able to find an occurrence within the file. If not, it will return a -1.


    The Strings.h has the function Get_Line which is defined and the error
    is shown below:

    Strings.h:

    void get_line( istream & );


    > ld: Unresolved:
    > String::get_line(std::basic_istream <char,
    > std::char_traits<char>&>)



    > The code segment follows this structure and does compile:



    #include "Strings.h"
    #include <fstream.h>

    int main( int argc, char** argv)
    {
    fstream File;
    Strings End_Of_Line;
    File.open("/users/netgrps/sf305/test.txt", ios::in);
    Strings output = "", Stored_Message="", Line(End_Of_Line);
    int num_of_hits=0;


    while( ! File.eof())

    {
    if(Line.findStr("Stat:") != 0)
    {
    num_of_hits++;

    if(num_of_hits == 2)
    break;
    }

    if(num_of_hits == 1)
    Stored_Message += Line;

    Line.get_line(File);
    End_Of_Line = Line;

    }
    cout << Stored_Message << endl;
    }

    I opened the library that Strings.h is compiled into with the command
    "nm -print" and the method exists. Any idea what may be the problem?
     
    , Feb 13, 2007
    #1
    1. Advertisements

  2. red floyd Guest

    wrote:
    > Hi Everyone,
    >
    >> The problem that I have involves program that searches for a certain string within a file. As seen in the code, I have declared a Strings class which overrides the string class in C++. Inside of this class, it has a function called findStr (replaces the find in string.h) which will return a 0 when it is able to find an occurrence within the file. If not, it will return a -1.

    >
    > The Strings.h has the function Get_Line which is defined and the error
    > is shown below:
    >
    > Strings.h:
    >
    > void get_line( istream & );
    >
    >
    >> ld: Unresolved:
    >> String::get_line(std::basic_istream <char,
    >> std::char_traits<char>&>)

    >
    >
    >> The code segment follows this structure and does compile:

    >
    >
    > #include "Strings.h"
    > #include <fstream.h>


    Fstream.h is non-standard. Should be

    #include <fstream>
    using std::fstream;
    >
    > int main( int argc, char** argv)
    > {
    > fstream File;
    > Strings End_Of_Line;
    > File.open("/users/netgrps/sf305/test.txt", ios::in);
    > Strings output = "", Stored_Message="", Line(End_Of_Line);
    > int num_of_hits=0;
    >
    >
    > while( ! File.eof())
    >
    > {
    > if(Line.findStr("Stat:") != 0)
    > {
    > num_of_hits++;
    >
    > if(num_of_hits == 2)
    > break;
    > }
    >
    > if(num_of_hits == 1)
    > Stored_Message += Line;
    >
    > Line.get_line(File);
    > End_Of_Line = Line;
    >
    > }
    > cout << Stored_Message << endl;
    > }
    >
    > I opened the library that Strings.h is compiled into with the command
    > "nm -print" and the method exists. Any idea what may be the problem?
    >
     
    red floyd, Feb 13, 2007
    #2
    1. Advertisements

  3. wrote:
    > Hi Everyone,
    >
    >
    >> The problem that I have involves program that searches for a certain string within a file. As seen in the code, I have declared a Strings class which overrides the string class in C++. Inside of this class, it has a function called findStr (replaces the find in string.h) which will return a 0 when it is able to find an occurrence within the file. If not, it will return a -1.

    >
    >
    > The Strings.h has the function Get_Line which is defined and the error
    > is shown below:
    >
    > Strings.h:
    >
    > void get_line( istream & );
    >
    >
    >
    >> ld: Unresolved:
    >> String::get_line(std::basic_istream <char,
    >>std::char_traits<char>&>)

    >
    >
    >
    >>The code segment follows this structure and does compile:

    >
    >
    >
    > #include "Strings.h"
    > #include <fstream.h>
    >
    > int main( int argc, char** argv)
    > {
    > fstream File;
    > Strings End_Of_Line;
    > File.open("/users/netgrps/sf305/test.txt", ios::in);
    > Strings output = "", Stored_Message="", Line(End_Of_Line);
    > int num_of_hits=0;
    >
    >
    > while( ! File.eof())
    >
    > {
    > if(Line.findStr("Stat:") != 0)
    > {
    > num_of_hits++;
    >
    > if(num_of_hits == 2)
    > break;
    > }
    >
    > if(num_of_hits == 1)
    > Stored_Message += Line;
    >
    > Line.get_line(File);
    > End_Of_Line = Line;
    >
    > }
    > cout << Stored_Message << endl;
    > }
    >
    > I opened the library that Strings.h is compiled into with the command
    > "nm -print" and the method exists. Any idea what may be the problem?
    >


    Are you sure you are linking your program with the library containing
    get_line? Have you got consistant compiler flags etc. for the library
    compile and the program compile? Are you using shared libraries or
    static libaries, etc. etc.

    Clearly you are using your tools incorrectly but this isn't really a C++
    issue, it's a tools issue. Suggest you ask on a different group, and
    supply a bit more information. I'd guess it's the *way* you are
    compiling and linking, not the code that you are compiling and linking.

    john
     
    John Harrison, Feb 13, 2007
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Izak Pretorius
    Replies:
    2
    Views:
    1,899
    Christopher
    Sep 14, 2003
  2. Rodolphe
    Replies:
    4
    Views:
    1,308
    Rodolphe
    Oct 3, 2003
  3. Yoon-Soo Lee
    Replies:
    5
    Views:
    4,506
    Chris \( Val \)
    Jan 2, 2004
  4. We need more power captain
    Replies:
    3
    Views:
    6,991
    Muthu
    Feb 18, 2004
  5. Susan Baker
    Replies:
    2
    Views:
    1,123
    kelvSYC
    Jun 26, 2005
  6. Replies:
    2
    Views:
    503
    Ian Collins
    Feb 13, 2007
  7. Trent
    Replies:
    9
    Views:
    964
    Trent
    Jun 29, 2007
  8. Garrett Cooper
    Replies:
    0
    Views:
    762
    Garrett Cooper
    Feb 24, 2009
Loading...