i include "stdio.h" in my project, try to use 'fopen' function, but compiler says "undefined reference to 'fopen' "
FRDM-KL25Z, C, Processor Expert, UART I/0
Currently reading EWL C reference manual.....
Solved! Go to Solution.
Is it possible you are not PATHed properly (INCLUDEDIR= in Makefile) or have the wrong syntax?
Normally I'd use:
FILE * fp;
fp = fopen ("file.txt", "w+");
If this isn't the case can you post the entire outpuit from the compiler.
Hi Glen Fine,
Did you use the fopen correct in your bareboard ?
I think fopen should be used in the operation system, because it has the _EWL_OS_DISK_FILE_SUPPORT limit.
If you are used it ok, could you share your project with us?
Thank you very much!
Thanks for answering, iam doing C project for bachelor degree, wireless oscillometric blood pressure monitor ("WI-FI", tft lcd, sdcard, pump, valve, pressure sensor) , my supervisor explained that 'fopen' is function for mcu to open files for example in SDcard. My first intention was to use it to open files from PC and write to mcu flash, but as i know now this function isn't for that. Now, i'am looking for example how to configure code and enable 'fopen' for SPI microSD card.
Doublecheck that you have the include directory in the Makefile set properly or if you are compiling from the command line that you have the -i option pointing to the include directory. This is a common problem when learning how to compile. If you use a Makefile add
If you are compiling at the command line
gcc program-name.c -i/directory/path/to/include-files executable-name
fopen can be used for reading/writing from/to files and in some cases character devices (/dev/device) can be accessed via file I/O. Your SD card should be 'mounted' and listed in the device table (/dev). 'rm /dev' should enumaerate the devices.
Here is a link to an overview of C file I/O.
and here is an example for reading/writing using fopen.
If you are using Linux the sdcard will appear as a device somewhere in the device table. Read up on how Linux enumerates storage devices or devices in general. Read also how to point to a certain device and filename. If you execute your program in the same directory as the file it will be just the filename (i.e. tomas.txt) but if it is on another device (or directory) the filename may be something like /dev/sdc1/project1/tomas.txt (tomas.txt on an extedrnal sdcard). Once you understand how paritioning and the directory structure is enumerated in Linux then you will be able to locate any file on any device. In some cases you be able to access a device directly such as /dev/ttyS0 (for the first serial device) and read/write to the device
Welcome to the world of C programming. Having done embedded devices for the last decade I find that the C programming language is the language of choice for writing drivers, and can also be used for writing applications. C++ (a whole new bag of worms) can be used for writing applications as well.