Help with getline(...) call in C++ program

Hi,

I'm trying to compile a C++ program on my Powerbook G4 running the latest Mac OS X. I can compile the code on another linux system (Ubuntu) but I can't compile on the Mac. It says:

config_reader.cpp: In function 'int read_config(char*, int ( )(char, char*), int)':
config_reader.cpp:78: error: 'getline' was not declared in this scope
make: * [config_reader.o] Error 1

I am not sure what to make of this, since the program compiles flawlessly on Ubunutu.

Is there some extra library that I have to add?

Any help would be greatly appreciated, I really want to use my Mac to develop this application!

PowerBook G4, Mac OS X (10.4.7), 1.5 GB ram

Posted on Jul 7, 2006 4:11 PM

Reply
2 replies

Jul 8, 2006 2:45 PM in response to tricolaire

Thanks for the suggestions. I looked around and found out what my problem was.

First off it was a C program, not a C++ program. It was being compiled using g++ which threw me off for a bit of time.

So the getline() function is NOT part of standard C, it is a non-standard method available in GNU C. You can check to see if you have the getline() function be looking at your stdio.h file.

The Apple implementation of C does not include the getline function. As a workaround you can download the Xfree86 implementation of getline from:
http://cvsweb.xfree86.org/cvsweb/cvs/lib/getline.c

This thread helped me out quite a bit:
http://www.codecomments.com/archive243-2005-3-422531.html

-Kiran

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Help with getline(...) call in C++ program

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.