Scratchbox2 返回“函数 getline 的隐式声明”以及其他奇怪的行为

发布于 2024-12-21 00:11:40 字数 692 浏览 3 评论 0原文

我正在尝试为 maemo 环境(GNU)交叉编译我的应用程序。 正常编译应用程序时,一切正常,但是当通过 sb2 编译时,会出现以下警告:

$ 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'

我完全困惑为什么会发生这种情况,还有其他 getlines 在程序中起作用,我尝试定义变量_GNU_SOURCE 既在代码内部又在编译器命令中(不同时) 这是明显导致警告的代码行:

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

任何帮助将不胜感激,提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

┊风居住的梦幻卍 2024-12-28 00:11:40

问题解决了,我所要做的就是添加:

#define _GNU_SOURCE

每个头文件中,before stdio.h 被包含在内,真的非常简单。

我想这个信息被假设为程序员之间已知的,因为我无法在网上找到它,并且不得不亲自询问我的 C 编程教授,即使如此,我们在追踪源头时也遇到了一些麻烦。

不管怎样,谢谢。

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.

記柔刀 2024-12-28 00:11:40

更改编译器行以包含 -E 选项并重定向输出。使用此选项时,编译器只会预处理您的文件。对带有和不带 sb2 的两个版本都执行此操作。 getline() 通常可以在 stdio.h 中找到。通过查看两个版本的预处理输出,您应该能够看到 getline() 的包含位置。

Change your compiler line to include the -E option and redirect the output. The compiler will only pre-proccess your file when this option is used. Do this for both versions, with and without sb2. getline() is normally found in stdio.h. By viewing the preprocessed output from both versions, you should be able to see where getline() is being included from.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文