For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > February 2007 > Problem with C++ Compiling Error ld: Unresolved Error









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problem with C++ Compiling Error ld: Unresolved Error
stevenruiz@gmail.com

2007-02-12, 7:08 pm

Hi Everyone,

The problem that I have involves compiling two files. I've
received this error before and I understood that I was missing the
correct library. The error is as follows:

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

The code segment follows this structure:

#include <fstream>
#include "String.h"
#include <string>

function()
{
String val = "";
ifstream File;
int num_of_exits=0;

try
{
File.open(<path>, val);
while( ! File.eof())
{
//Searching for specific word
if( val.find("Exit") != string::npos)
num_of_exits++

//Searching for a word
getline(File, val)
}
}
catch(Exception& E)
{}
}


In my makefile, I have included the necessary libraries to compile. I
was able to confirm that the getline does exist with the nm
command. Is there any other reason why this would happen besides
not including the proper libraries or includes? Any ideas. Thanks.

Ian Collins

2007-02-12, 7:08 pm

stevenruiz@gmail.com wrote:
> Hi Everyone,
>
> The problem that I have involves compiling two files. I've
> received this error before and I understood that I was missing the
> correct library. The error is as follows:
>
> ld: Unresolved:
> String::getline(std::basic_istream <char,
> std::char_traits<char>&>, const &String String)
>

What is String? The linker can't find a member function, but your code
uses a normal function. Post a small, complete example that gives the
problem.

> The code segment follows this structure:
>
> #include <fstream>
> #include "String.h"
> #include <string>
>
> function()
> {
> String val = "";
> ifstream File;


Capitalised variable names aren't a good idea, they look like types.

--
Ian Collins.
Paul Pluzhnikov

2007-02-12, 10:08 pm

stevenruiz@gmail.com writes:

> In my makefile, I have included the necessary libraries to compile. I
> was able to confirm that the getline does exist with the nm
> command.


Any 'getline' or the particular getline that gives you the error?
What compiler did you use, and what did "nm" tell you about the
existing getline?

> Is there any other reason why this would happen besides
> not including the proper libraries or includes?


Sure: incorrect link line. Order of objects/sources and libraries
on the link line matters; libraries must follow objects, not the
other way around. More info here:
http://webpages.charter.net/ppluzhnikov/linker.html

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Thomas Maier-Komor

2007-02-13, 8:09 am

stevenruiz@gmail.com schrieb:
> Hi Everyone,
>
> The problem that I have involves compiling two files. I've
> received this error before and I understood that I was missing the
> correct library. The error is as follows:
>
> ld: Unresolved:
> String::getline(std::basic_istream <char,
> std::char_traits<char>&>, const &String String)
>
> The code segment follows this structure:
>
> #include <fstream>
> #include "String.h"
> #include <string>
>
> function()
> {
> String val = "";
> ifstream File;
> int num_of_exits=0;
>
> try
> {
> File.open(<path>, val);
> while( ! File.eof())
> {
> //Searching for specific word
> if( val.find("Exit") != string::npos)
> num_of_exits++
>
> //Searching for a word
> getline(File, val)
> }
> }
> catch(Exception& E)
> {}
> }
>
>
> In my makefile, I have included the necessary libraries to compile. I
> was able to confirm that the getline does exist with the nm
> command. Is there any other reason why this would happen besides
> not including the proper libraries or includes? Any ideas. Thanks.
>


What are String, and Exception? I only know std::string and
std::exception - you would be better off doing copy paste, when asking
such a question...

Are you by any chance linking either with ld directly or with your C
compiler? In this case you will get all kinds of weird error messages.
Try linking with your C++ compiler.

HTH,
Tom
Ulrich Eckhardt

2007-02-13, 7:08 pm

stevenruiz@gmail.com wrote:
> The problem that I have involves compiling two files. I've
> received this error before and I understood that I was missing the
> correct library. The error is as follows:
>
> ld: Unresolved:
> String::getline(std::basic_istream <char,
> std::char_traits<char>&>, const &String String)
>
> The code segment follows this structure:
>
> #include <fstream>
> #include "String.h"
> #include <string>
>
> function()
> {
> String val = "";
> ifstream File;


Hmmm, up to here I start to wonder how you got this past a C++ compiler. In
particular the implicit 'int' returntype of the function and the
lacking 'std::' qualification of the fstream are so pre-standard that your
compiler must be a real dinosaur.

I'd suggest getting a recent GCC, which runs on most platforms, and a good
book on C++ (pick one from the reviews at ACCU).

> File.open(<path>, val);


Okay, got it now, you didn't cut'n'paste the code. IOW, your example is
useless, it's impossible to diagnose one thing when the other thing fails.

> while( ! File.eof())
> {
> //Searching for specific word
> if( val.find("Exit") != string::npos)
> num_of_exits++
>
> //Searching for a word
> getline(File, val)
> }


Wrong, use
while(getline( in, str)) {
/*use str*/
}

Uli

--
http://www.erlenstar.demon.co.uk/unix/
stevenruiz@gmail.com

2007-02-13, 7:08 pm

On Feb 13, 3:43 pm, Ulrich Eckhardt <dooms...@knuut.de> wrote:
> stevenr...@gmail.com wrote:
>
>
>
>
>
> Hmmm, up to here I start to wonder how you got this past a C++ compiler. In
> particular the implicit 'int' returntype of the function and the
> lacking 'std::' qualification of the fstream are so pre-standard that your
> compiler must be a real dinosaur.
>
> I'd suggest getting a recent GCC, which runs on most platforms, and a good
> book on C++ (pick one from the reviews at ACCU).
>
>
> Okay, got it now, you didn't cut'n'paste the code. IOW, your example is
> useless, it's impossible to diagnose one thing when the other thing fails.
>
>
>
> Wrong, use
> while(getline( in, str)) {
> /*use str*/
> }
>
> Uli
>
> --http://www.erlenstar.demon.co.uk/unix/- Hide quoted text -
>
> - Show quoted text -


Thanks for reviewing this post. I have a more recent post of the
problem that is shown here. It is dated Feb 13 at 2:00pm. I included
details about what is being used, classes used, and it also compiles.
Hopefully you can give me hints based on that post. Thank you
everyone.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com