简体   繁体   English

函数“getline”的隐式声明甚至认为是

[英]implicit declaration of function 'getline' even thought it is

I'm currently having some problems with getline() in c.我目前在 c 中使用 getline() 遇到一些问题。 I know it's not a standard C function, however I am using the proper resources according to what I've seen online.我知道这不是标准的 C 函数,但是根据我在网上看到的内容,我正在使用适当的资源。

I have both:我有两个:

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

However I am still having problems compiling, it gives me this output:但是我仍然在编译时遇到问题,它给了我这个输出:

main.c: In function 'read-file':
main.c:46:17: warning: implicit declaration of function 'getline' [-Wimplicit-function-declaration]
C:\Users\Miguel\AppData\Local\Temp\cc6aYESe.o:main.c:(.text+0x85): undefined reference to `getline'
collect2.exe: error: ld returned 1 exit status

I can't seem to figure out what's wrong, I've seen several problems like this, however no solution seems to apply.我似乎无法弄清楚出了什么问题,我见过几个这样的问题,但似乎没有任何解决方案适用。

try with the following preprocessor sentence: #define _POSIX_C_SOURCE 200809L尝试使用以下预处理器语句: #define _POSIX_C_SOURCE 200809L

"It allows you to use functions that are not part of the standard C library but are part of the POSIX.1 (IEEE Standard 1003.1) standard. Using the macros described in feature_test_macros allows you to control the definitions exposed by the system header files." “它允许您使用不属于标准 C 库但属于 POSIX.1(IEEE 标准 1003.1)标准一部分的函数。使用 feature_test_macros 中描述的宏允许您控制系统头文件公开的定义。 ”

ref: What does #define _POSIX_SOURCE mean?参考: #define _POSIX_SOURCE 是什么意思?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM