对c中的“ getline”的未定义引用#define _GNU_SOURCE

问题描述 投票:0回答:1

我想用C来吸引读者,因为我是win 7的新手,我使用所有类型的库,但是没有用。这就是我所做的:

#include "linkedlist.h"
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    FILE * fp;
    char * line = NULL;
    size_t len = 0;
    ssize_t read;

    fp = fopen("tableros.txt", "r");
    if (fp == NULL)
        exit(EXIT_FAILURE);

    while ((read = getline(&line, &len, fp)) != -1) {
        printf("Retrieved line of length %zu:\n", read);
        printf("%s", line);
    }

    fclose(fp);
    if (line)
        free(line);
    exit(EXIT_SUCCESS);
}

但是此代码给了我相同的错误undefined reference to getline in c,我真的不知道可能是什么错误,所以我尝试使用发现here的其他库,这是另一次尝试,是相同的代码,但是使用[C0 ]:

#define _POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700

所以我真的不知道可能是什么,在这里我会放上我的编辑器的屏幕快照,以防问题可能是编译器或其他我没有看到的东西:(:#include "linkedlist.h" #define _POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700 #include <stdio.h> #include <stdlib.h> int main(void) { FILE * fp; char * line = NULL; size_t len = 0; ssize_t read; fp = fopen("tableros.txt", "r"); if (fp == NULL) exit(EXIT_FAILURE); while ((read = getline(&line, &len, fp)) != -1) { printf("Retrieved line of length %zu:\n", read); printf("%s", line); } fclose(fp); if (line) free(line); exit(EXIT_SUCCESS); } 这是C为我提供的更多详细信息的错误:

enter image description here
c windows-7 getline stdio
1个回答
0
投票

C:\Users\RAULDE~1\AppData\Local\Temp\cctm12ki.o tablero.c:(.text+0x78): undefined reference to `getline' C:\Users\Raul del Rio\Desktop\archivos c sist oper\collect2.exe [Error] ld returned 1 exit status 的源代码(有多个源资源,可以在以下位置找到:

getline()
© www.soinside.com 2019 - 2024. All rights reserved.