Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Problems with ld: Unresolved error C++ compiling error

Reply
Thread Tools

Problems with ld: Unresolved error C++ compiling error

 
 
stevenruiz@gmail.com
Guest
Posts: n/a
 
      02-13-2007
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?

 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      02-13-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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?
>

 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      02-13-2007
(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Cross-compiling error when compiling 2.6.1... Garrett Cooper Python 0 02-24-2009 09:47 PM
Cross-compiling error when compiling 2.6.1... Garrett Cooper Python 0 02-24-2009 08:55 PM
What is Error 1 error LNK2019: unresolved external symbol ???? Trent C++ 9 06-29-2007 08:32 PM
Problem with C++ Compiling Error ld: Unresolved Error stevenruiz@gmail.com C++ 2 02-13-2007 12:01 AM
Re: unresolved external symbol error. Need help! John Harrison C++ 0 07-20-2003 07:18 PM



Advertisments