CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2012
    Posts
    1

    Unable to compile C lib of FatFS with C++ Project

    Is there a C++ version of the FatFS library?

    I am trying to incorporate fatfs into a cpp project and I havent been able to compile the project even though I added the

    #ifdef __cplusplus
    extern "C"
    {
    #endif

    in the header file. I may have missed something. Has anyone been able to do this?

    Here is the section where I added the extern

    #ifdef __cplusplus
    extern "C"
    {
    #endif

    /*-----------------------------------------------------*/
    /* FatFs module application interface */

    extern FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
    extern FRESULT f_open (FIL*, const char*, BYTE); /* Open or create a file */
    extern FRESULT f_read (FIL*, void*, WORD, WORD*); /* Read data from a file */
    extern FRESULT f_write (FIL*, const void*, WORD, WORD*); /* Write data to a file */
    extern FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */
    extern FRESULT f_close (FIL*); /* Close an open file object */
    extern FRESULT f_opendir (DIR*, const char*); /* Open an existing directory */
    extern FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */
    extern FRESULT f_stat (const char*, FILINFO*); /* Get file status */
    extern FRESULT f_getfree (const char*, DWORD*, FATFS**); /* Get number of free clusters on the drive */
    extern FRESULT f_sync (FIL*); /* Flush cached data of a writing file */
    extern FRESULT f_unlink (const char*); /* Delete an existing file or directory */
    extern FRESULT f_mkdir (const char*); /* Create a new directory */
    extern FRESULT f_chmod (const char*, BYTE, BYTE); /* Change file/dir attriburte */
    extern FRESULT f_rename (const char*, const char*); /* Rename/Move a file or directory */
    extern FRESULT f_mkfs (BYTE, BYTE, BYTE); /* Create a file system on the drive */


    /* User defined function to give a current time to fatfs module */

    extern DWORD get_fattime (void); /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */
    /* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */

    #ifdef __cplusplus
    }
    #endif
    Reply to this

  2. #2
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: Unable to compile C lib of FatFS with C++ Project

    What compiler do you use?
    What error messages do you get?

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Unable to compile C lib of FatFS with C++ Project

    extern "C" does not turn a C++ compiler into a C compiler.

    It merely tells the C++ compiler to export any functions using a C naming convention rather than the C++ "name mangling".

    Whether or not you can get your C++ compiler to fully accept C code is another matter. Some do, some don't. Some require a compiler parameter, and some do this by going by the filename (a .c file is C code, and a .cpp is C++ code).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured