• AVR Freaks

Hot!How to "Provide an app-specific implementation of int open(...)"

Author
Memen
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2017/04/08 12:17:32
  • Location: 0
  • Status: offline
2019/04/11 10:39:08 (permalink)
0

How to "Provide an app-specific implementation of int open(...)"

Is it possible to provide custom fopen, fclose, etc. functions to xc32 in order to work with e.g. C++ fstreams?
 
Without any change, using the following line of code
std::ifstream myfilestream("file.txt");
gives a
 warning: Linking stub open(). Hint: Provide an app-specific implementation of int open (const char *buf, int flags, int mode)
.
 
The FatFS I found provides these f_open() etc functions, but how to "Provide this app-specific implementation" to the linker?
I tried adding a simple
int open (const char *buf, int flags, int mode)
{
    return 0;
}
but this does not change anything (same warning). I read that this is called 'retargetting', but I can only find - with difficulty - examples for ARM, not XC32. Does anyone have an example or link to related compiler documentation?
 
1: the fatfs used here is the "ELM by Chan", cannot post a link
2: this should probably in MPLAB XC32 forum, something went wrong during posting
post edited by Memen - 2019/04/11 10:47:33
#1

2 Replies Related Threads

    Mysil
    Super Member
    • Total Posts : 3325
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: How to "Provide an app-specific implementation of int open(...)" 2019/04/11 13:24:52 (permalink)
    0
    Hi,
    "Provide an app-specific implementation..."
    means that you do it yourself:
    This is a empty shell:
    int open (const char *buf, int flags, int mode)
    {
        return 0;
    }

    You put any translation needed inside, to call functions in FatFs code.
     
    C language and the linker do not allow two functions with the same name in a program,
    so you must also find and remove the code giving the warning.
    The warning comes from compilation of source code, so it is somewhere in there.
    You may make the warning into comments,
    or there may be a macro symbol you can define to make the warning go away.
     
    The warning may actually not be a problem at all, it may be just a reminder about will be needed.
     
        Mysil
    #2
    Memen
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2017/04/08 12:17:32
    • Location: 0
    • Status: offline
    Re: How to "Provide an app-specific implementation of int open(...)" 2019/04/11 15:41:39 (permalink)
    0
    Hi Mysil,
     
    Thanks! That gives some more direction, but it is still unclear to me
    - where are the current declarations/definitions/prototypes of these functions? Looking in the <fstream> header I see for example the line
    extern _Filet *_Fiopen(const char *, ios_base::openmode, int);
    , which is used later in that header and a call to fclose() as well. I cannot find definitions of either, so where can I find what the parameter and return types and exact function names should be? (I expect function names for open, close, read, write, sync, seek, and maybe more?)
     
    - does it mean the functions should be declared extern "C" when I want to use these in C++ or are there C++ variants as well? (especially since c++ seems to expect a _Filet instead of an int as return type from open)
     
    Changed the test code to
    extern "C" int open (const char *buf, int flags, int mode)
    {
        return 1;
    }
    , which gets actually executed when opening the stream, so that's a good start already!
     
    Best regards,
    post edited by Memen - 2019/04/11 15:45:18
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5