Operating System - HP-UX
1827924 Members
2783 Online
109972 Solutions
New Discussion

Error in linking a program that includes getline function

 
SOLVED
Go to solution
guptaanunay
Occasional Contributor

Error in linking a program that includes getline function

Hi all,

I am trying to compile this test program on my HP machine:-

#include
#include
int main(void)
{
FILE * fp;
char * line = NULL;
size_t len = 0;
ssize_t read;
fp = fopen("/etc/motd", "r");
if (fp == NULL)
exit(2);
while ((read = getline(&line, &len, fp)) != -1) {
printf("Retrieved line of length %zu :\n", read);
printf("%s", line);
}
if (line)
free(line);
return 1;
}


This is reporting the following errors on compilation/linking:-
/usr/ccs/bin/ld: Unsatisfied symbols:
getline (first referenced in h.o) (code)

Can anybody suggest something?

Thanks,
Anunay
2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Error in linking a program that includes getline function

HP-UX doesn't have getline() although the could get it as a Gnu library function. You probably are porting from Linux; your better choice would be fgets() which is a standard function.

fgets() does not automatically allocate a buffer:

#define BSIZE 1024

char line[BSIZE],*p = NULL;

p = fgets(line,sizeof(line),fp);
while (p != NULL)
{
(void) printf("%s",line);
p = fgets(line,sizeof(line),fp);
}
(void) fclose(fp);
If it ain't broke, I can fix that.
guptaanunay
Occasional Contributor

Re: Error in linking a program that includes getline function

Thanks Clay,

Your solution solved my problem perfectly.
Anunay