Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference to flock, flockfile (IDFGH-409) #2565

Closed
siara-cc opened this issue Oct 15, 2018 · 3 comments
Closed

undefined reference to flock, flockfile (IDFGH-409) #2565

siara-cc opened this issue Oct 15, 2018 · 3 comments

Comments

@siara-cc
Copy link

Environment

  • Core: ESP-WROOM32
  • IDF version: v3.1
  • Development Env: Arduino IDE, make(esp-idf)
  • Operating System: MacOS sierra 10.12.6
  • Power Supply: USB

Problem Description

Unable to use functions such as flock, flockfile. There is no compilation error, but a linker error is thrown such as "undefined reference to `flockfile' collect2: error: ld returned 1 exit status"

Expected Behaviour

Links without error and binary file generated and file locking possible.

Actual Behaviour

See problem description. Same behaviour is seen in both Arduino IDE and using make with ESP-IDF 3.1 installed.

Steps to reproduce

Paste following code in Arduino IDE New sketch with any ESP32 board selected.

Code to reproduce this issue

#include <stdio.h>
#include <fcntl.h>
#include "FS.h"
#include "SD_MMC.h"

void setup() {

    Serial.begin(115200);
    if (!SD_MMC.begin()){
        Serial.println("Card Mount Failed");
        return;
    }

    FILE *fp = fopen("/sdcard/test.txt", "r+");
    flock(fileno(fp), LOCK_EX);
    flock(fileno(fp), LOCK_UN);
    fclose(fp);

}

void loop() {
}
@siara-cc
Copy link
Author

Does fcntl() work for file locking? It seems to link without problems.

@igrr
Copy link
Member

igrr commented Oct 16, 2018

On desktop platforms, flock creates a lock which works between processes. Here in ESP-IDF we have only one process, so an implentation of flock would be a no-op.

flockfile, on the other hand, can be used to lock between threads (tasks in FreeRTOS), and is certainly useful. It is not exposed at the moment but we will certainly provide this definition.

fcntl locking is also between processes, as far as I understand, so it would also be a no-op in ESP-IDF.

@Alvin1Zhang Alvin1Zhang changed the title undefined reference to flock, flockfile [TW#26798] undefined reference to flock, flockfile Oct 16, 2018
@projectgus projectgus changed the title [TW#26798] undefined reference to flock, flockfile undefined reference to flock, flockfile (IDFGH-409) Mar 12, 2019
@luanmm
Copy link

luanmm commented Jul 1, 2019

It is something that would be very useful for a project I'm working on. We may expect it to be done soon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants