undefined reference to `getline' in c
我正在学习在C编程中使用getline,并尝试了http://crasseux.com/books/ctutorial/getline.html中的代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int atgc, char *argv[]) { int bytes_read = 1; int nbytes = 10; char *my_string; my_string = (char *)malloc(nbytes+1); puts("Please enter a line of text"); bytes_read = getline(&my_string, &nbytes, stdin); if (bytes_read == -1) { puts ("ERROR!"); } else { puts ("You typed:"); puts (my_string); } return 0; } |
但是,问题在于,编译器不断返回以下错误:对" getline"的未定义引用。
你能告诉我问题是什么吗? 谢谢!
我正在使用Win7 64bit + Eclipse Indigo + MinGW
其他答案涵盖了大部分内容,但是存在几个问题。首先,
此外,
做出更改后,您的程序可以在我的系统上编译并正常运行。
我也在使用MinGW。我检查了MinGW头文件,并且
1 | _POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700 |
对于glibc 2.10或更高版本,
1 | _GNU_SOURCE |
在那之前。