0

i was tring to make a reader in C because i am new in this lenguage in win 7, i use all kind of library but nothing work. This is what i did:

#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);
}

but this code give me the same error undefined reference to getline in c, i really don t know what error could be, so i try with other library that i find here here is the other try, is the same code but with #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);
}

so i really don t know what could be, here i gonna put a screenshot of my editor in the case that the problem could be a compiler or another thing that i didn t see :( : enter image description here here are the errors that C give me with more detail:

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
mrpepo877
  • 490
  • 6
  • 23
  • Did you try like in the example code here https://en.cppreference.com/w/c/experimental/dynamic/getline ? – Yunnosch Apr 05 '20 at 05:30
  • i tried now and don t work :( – mrpepo877 Apr 05 '20 at 05:33
  • 1
    `getline()` is a POSIX function that might not be present on whatever Windows libc your program is linking against. – Shawn Apr 05 '20 at 07:18
  • so what do you propose :(?, because i need some place to test my codes – mrpepo877 Apr 05 '20 at 07:35
  • this question already has an answer [getline](https://stackoverflow.com/questions/27381903/where-how-to-get-the-getline-function-if-it-is-missing-from-stdio-h) – user3629249 Apr 05 '20 at 20:40
  • 1
    Does this answer your question? [Where/how to get the "getline" function if it is missing from stdio.h?](https://stackoverflow.com/questions/27381903/where-how-to-get-the-getline-function-if-it-is-missing-from-stdio-h) – user3629249 Apr 05 '20 at 20:40
  • You can also use [Cygwin](https://www.cygwin.com/), if you want port applications which uses POSIX functions. –  Apr 05 '20 at 21:02

0 Answers0