Scratchbox2 returns "Implicit declaration of function getline", among other weird behaviour

Jaime Borondo picture Jaime Borondo · Dec 12, 2011 · Viewed 12.4k times · Source

I'm trying to cross compile my application for the maemo environment (GNU). When compiling the application normally, everything works fine, however when it's compiled through sb2 the following warning comes up:

$ sb2 gcc -D_GNU_SORCE -o app -Wall -g -I.......//don't think this is relevant

 In file included from wifi_collector_menu.c:50:
 wifi_collector_list.c: In function `show_net_apns':
 wifi_collector_list.c:777: warning: implicit declaration of function `getline'

I am completely confused as to why this happens, there are other getlines that do work in the program, i have tried to define the variable _GNU_SOURCE both inside the code and in the compiler command (not at the same time) This is the line of code which causes the warning apparently:

size_t bytesnum = MAX_ESSID;
size_t bytes_read;
char *netname = NULL;
printf("Enter name of selected network:");
bytes_read=getline(&netname,&bytesnum,stdin);//This line

Any help would be appreciated, thanks in advance.

Answer

Jaime Borondo picture Jaime Borondo · Dec 13, 2011

Problem solved, all I had to do was add:

#define _GNU_SOURCE

In each header file, before stdio.h was included, very simple really.

I guess this info is assumed known between programmers as i was unable to find it anywhere online, and had to ask my C programming professor personally, and even then we had some trouble tracing the source.

Thanks anyway.