Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getline

Status
Not open for further replies.

rabidus

Programmer
Nov 1, 2005
5
US
The top of my file I'm compiling looks like this:

#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[])


When I compile this is my output:

$ gcc -o stage1 proj3.c
Undefined first referenced
symbol in file
getline /var/tmp//ccyGAN2k.o
ld: fatal: Symbol referencing errors. No output written to stage1
collect2: ld returned 1 exit status

Any ideas what could be causing this?
 
Thanks for posting the non-relevant part of your programme - that helps a lot !

Without seeing the code that has the error in it, I can only guess ... but there is no function called "getline" in stdio.h or string.h - maybe thats your problem ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
I think some of your code is missing - and please use code tags - it makes it easier to read.

BTW don't you mean gets rather than getline?

Columb Healy
 
Well, the rest of my code is irrelevant, as the symbol is undefined. I apologize for the lack of code tags. This is the function that I'm trying to call:


Yes, the problem does seem to be that the function isn't defined in stdio.h or string.h. However I'm unable to find which library it is located in.

Thanks for such quick responses!
 
The page you reference states that
All these functions are declared in stdio.h.
but you've included this already. I'm not enough of a gcc expert th hjelp further.

Columb Healy
 
This is all on a Solaris machine. I grepped stdio.h on my local linux machine (which I'm sure has all the up to date libraries) and it didn't find any reference to getline. The man page for stdio doesn't mention it either! I suppose I will look for another solution for the time being.

Thanks for your time!
 
Code:
#include <stdio.h>

int main(int argc, char* argv[]) {
   char** pp_bla;
   size_t t_bla;
   getline(pp_bla, &t_bla, stdin);
}

Can you compile and link this ?
If not, post your GCC version, and platform ...

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Same output as before when I try to compile and link that code.

Gcc version is 3.3.2
Platform is Sun Solaris 2.9
 
[tt]getline[/tt] is declared in the C++ header [tt]<istream>[/tt]. It is part of the [tt]std[/tt] namespace.
[link]http://dinkumware.com/manuals/reader.aspx?lib=cpl&h=istream.html#basic_istream::getline[/url]

[tt]getline[/tt] is also overloaded for use with [tt]std::string][/tt].
 
It seems to be a problem with this specific machine, ssh'd into another machine with gcc4 and it worked. Odd because our entire CS department uses this machine to do lots of work on, funny that there is such a problem...
 
You may need to define a feature test macro to use [tt]getline[/tt].

On my Linux machine, I need to do this
Code:
[COLOR=red]#define _GNU_SOURCE[/color]
#include <stdio.h>
to be able to use [tt]getline[/tt].
 
By the way, the link I gave incedentally uses [tt]getline[/tt] as an example of why feature test macros are needed to access some functions.
 
This is not a compilation error, it's a linker error. Therefore I would be looking for which library you should find your "getline" function in and whether it's available to your linker.


Trojan.
 
Status
Not open for further replies.

Similar threads

Replies
1
Views
46

Part and Inventory Search

Sponsor

Back
Top