2

I'm trying to compile a pre-existing c++ package on my mac osx leopard machine, and get the following error:

    error: no matching function for call to 'getline(char**, size_t*, FILE*&)'

This is probably because getline() is a GNU specific extension.

Can I somehow make the osx default g++ compiler recognize such GNU specific extensions?

(if not, I could always supply my own implementation or GNUs original one, but I prefer to have a "cleaner" solution if possible)

Yoav
  • 501
  • 1
  • 7
  • 12

3 Answers3

5

getline is defined in stdio.h in glibc version 2.10 and later, but not in earlier versions, nor (so far; added 10.5 definitely didn't have getline, and 10.7 definitely does) in the BSD derived libc.

The change in the GNU libraries came about because of a change in the POSIX 2008 standard, which now includes getline.

Presumably, this will propogate to other libc over time. In the mean time, I understand that it is causing trouble for a lot of projects.

You can download a stand alone version from GNU.

dmckee --- ex-moderator kitten
  • 98,632
  • 24
  • 142
  • 234
1

Generally, the solution is to use autoconf or some similar tool to determine whether the current platform already has getline or not, and supply your own definition only when needed.

Example:

# configure.ac
AC_CHECK_FUNCS([getline])

// compat.h
#include "config.h"
#ifndef HAVE_GETLINE
ssize_t getline(char **lineptr, size_t *n, FILE *stream);
#endif

// getline.c
ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
    /* definition */
}

# Makefile.am
program_LDADD = $(if $(HAVE_GETLINE),,getline.o)

or something along those lines, you'll have to adjust it to match your own program.

ephemient
  • 198,619
  • 38
  • 280
  • 391
0

I'm not sure I've ever seen that specific definition of 'getline' here is the one I know of which uses c++ streams+strings.

http://www.cplusplus.com/reference/string/getline/

DeusAduro
  • 5,971
  • 5
  • 29
  • 36