Please change file extension from *.c to .cpp.
I am trying to build a very simple piece of code for mbed. My code starts with #include "mbed.h" which includes platform.h. When running platformio run I get the following error:
.pioenvs/nucleo_l053r8/FrameworkMbedInc-250686161/platform.h:25:19: fatal error: cstddef: No such file or directory
#include <cstddef>
^
compilation terminated
I'm on ubuntu trusty (14.04), I read forum posts here and there that say I should upgrade to arm-none-eabi-gcc version 4.9.3, but this doesn't solve the problem.
I removed platformio entirely, reinstalled it with pip in a virtualenv, but no luck.
I eventually fixed the issue by adding
build_flags = -I/home/laurent/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/4.8.3/ -I/home/laurent/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/4.8.3/arm-none-eabi/
to my platformio.ini, but I don't feel like it's the right solution :)
Did I miss a step in the installation, or is this a bug? (maybe not with platformio...)
@valeros is this a bug with toolchain?
Hi @LaurentS !
Could you provide your project, please?
My code is a single file, copied from mbed Hello World at https://developer.mbed.org/handbook/mbed-SDK:
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
while(1) {
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}
}
It is compiled in a virtual env installed with:
$ mkvirtualenv pio_venv
$ pip install platformio
$ platformio init -b nucleo_l152re
$ platformio run
I actually fixed the problem by renaming src/main.c to src/main.cpp. If this is expected behaviour, please accept my apologies for the waste of time.
versions just in case:
$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20150529 (release) [ARM/embedded-4_9-branch revision 227977]
$ arm-none-eabi-g++ --version
arm-none-eabi-g++ (GNU Tools for ARM Embedded Processors) 4.9.3 20150529 (release) [ARM/embedded-4_9-branch revision 227977]
mbed is c++-based framework. You should use *.cpp extension.
Hy, i got the same problem, i used this tutorial https://developer.mbed.org/users/noritsuna/notebook/mbed-os-on-an-emulatorqemu/
I have 4.9.3 arm-none-eabi-gcc and when i try to '$yotta build' then crash the building.
@polaroi8d please share here the code which allows us to reproduce this issue. Thanks.
@ivankravets sorry for not respoding. Meanwhile i fixed the problem... I downloaded a new toolchain from https://launchpad.net/gcc-arm-embedded/+download and worked with this. ( After this, came up an other problem, the build directory hitched with the building process... fix: delet the building directory )
Why you don't use built-in PlatformIO toolchain?
I am having the same problem in Debian Testing with the simple code above and the plugin for Atom.
@crespum Please take a look at official PlatformIO IDE for Atom package https://atom.io/packages/platformio-ide
@ivankravets I found your samples and the only difference is that I was using main.c and you use main.cpp. Saving it as a C++ file solved this problem.
@crespum I've added comment about it above https://github.com/platformio/platformio/issues/301#issue-110306963
Hi @ivankravets
Although my file use cpp extension, but it's still can't find cstddef, here my logs:
Processing bluepill_f103c8 (platform: ststm32; framework: mbed; board: bluepill_f103c8)
Verbose mode can be enabled via
-v, --verboseoption
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/bluepill_f103c8.html
PLATFORM: ST STM32 5.7.0 > BluePill F103C8
HARDWARE: STM32F103C8T6 72MHz, 20KB RAM, 64KB Flash
DEBUG: Current (stlink) External (blackmagic, jlink, stlink)
PACKAGES: toolchain-gccarmnoneeabi 1.70201.0 (7.2.1), framework-mbed 5.51401.191023 (5.14.1)
Collecting mbed sources...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Looking for FATFileSystem library in registry
Conflict: More than one library has been found by request {"requirements": null, "name": "FATFileSystem"}:
FatFileSystem
===Automatically chose the first available library (use--interactiveoption to make a choice) =========ID: 385
Updated FAT File System driver. Features include: * Updated to R0.09 - Sep 06, 2011 [[http://elm-chan.org/fsw/ff/00index_e.html]] * Bug fixes from StГ©phane Bausseron * [[http://mbed.org/forum/mbed/topic/2273/?page=1#comment-11521]] *...
Keywords: fat, file, filenames, fixes, long, system
Compatible frameworks: mbed
Compatible platforms: Atmel SAM, Freescale Kinetis, Maxim Integrated MAX32, Nordic nRF51, Nordic nRF52, NXP LPC, Silicon Labs EFM32, ST STM32, Teensy, WIZNet W7500
Authors: Adam GreenFatFileSystem
ID: 201
Local copy of the FatFileSystem.
Keywords: fat
Compatible frameworks: mbed
Compatible platforms: Atmel SAM, Freescale Kinetis, Maxim Integrated MAX32, Nordic nRF51, Nordic nRF52, NXP LPC, Silicon Labs EFM32, ST STM32, Teensy, WIZNet W7500
Authors: Shinichiro NakamuraFatFileSystem
ID: 206
Updated get_fattime to use rtc and provide a date/time. This has been an annoying missing feature.
Keywords: fatfilesystem
Compatible frameworks: mbed
Compatible platforms: Atmel SAM, Freescale Kinetis, Maxim Integrated MAX32, Nordic nRF51, Nordic nRF52, NXP LPC, Silicon Labs EFM32, ST STM32, Teensy, WIZNet W7500
Authors: Andrew LindsayFatFileSystem
ID: 3585
Some library needed for things? Licence unknown
Keywords: fatfilesystem
Compatible frameworks: mbed
Compatible platforms: Atmel SAM, Freescale Kinetis, Maxim Integrated MAX32, Nordic nRF51, Nordic nRF52, NXP LPC, Silicon Labs EFM32, ST STM32, Teensy, WIZNet W7500
Authors: Tom BloorFound: https://platformio.org/lib/show/385/FatFileSystem
LibraryManager: Installing id=385
FatFileSystem @ 6ceefe1c53 is already installed
Found 6 compatible libraries
Scanning dependencies...
Dependency Graph
|--
| |--
Building in release mode
Compiling .pio\build\bluepill_f103c8\FrameworkMbed\drivers\source\AnalogIn.o
....
....
Compiling .pio\build\bluepill_f103c8\lib7fc\FatFileSystem_ID385\FATDirHandle.o
Compiling .pio\build\bluepill_f103c8\lib7fc\FatFileSystem_ID385\FATFileHandle.o
Compiling .pio\build\bluepill_f103c8\lib7fc\FatFileSystem_ID385\FATFileSystem.o
Compiling .pio\build\bluepill_f103c8\lib7fc\FatFileSystem_ID385\diskio.o
Compiling .pio\build\bluepill_f103c8\lib7fc\FatFileSystem_ID385\ff.o
Compiling .pio\build\bluepill_f103c8\lib7fc\FatFileSystem_ID385\option\ccsbcs.o
In file included from C:\Users\fmukhtarif.platformio\packages\framework-mbed\platform/FileSystemLike.h:20:0,
from .pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATFileSystem.h:22,
from .pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\diskio.c:11:
C:\Users\fmukhtarif.platformio\packages\framework-mbed/platform/platform.h:21:10: fatal error: cstddef: No such file or directory
#include
^~~
compilation terminated.
Compiling .pio\build\bluepill_f103c8\libcea\SDFileSystem-8db0d3b02cec\SDFileSystem.o
* [.pio\build\bluepill_f103c8\lib7fc\FatFileSystem_ID385\diskio.o] Error 1
In file included from .pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATDirHandle.h:8:0,
from .pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATDirHandle.cpp:9:
C:\Users\fmukhtarif.platformio\packages\framework-mbed\platform/DirHandle.h: In member function 'virtual size_t mbed::DirHandle::size()':
C:\Users\fmukhtarif.platformio\packages\framework-mbed\platform/DirHandle.h:97:41: error: invalid use of incomplete type 'struct mbed::dirent'
struct dirent ent = new struct dirent;
^~
C:\Users\fmukhtarif.platformio\packages\framework-mbed\platform/DirHandle.h:64:33: note: forward declaration of 'struct mbed::dirent'
virtual ssize_t read(struct dirent *ent) = 0;
^~
C:\Users\fmukhtarif.platformio\packages\framework-mbed\platform/DirHandle.h:105:16: warning: possible problem detected in invocation of delete operator: [-Wdelete-incomplete]
delete ent;
^
C:\Users\fmukhtarif.platformio\packages\framework-mbed\platform/DirHandle.h:97:24: warning: 'ent' has incomplete type
struct dirent *ent = new struct dirent;
^~~
C:\Users\fmukhtarif.platformio\packages\framework-mbed\platform/DirHandle.h:64:33: note: forward declaration of 'struct mbed::dirent'
virtual ssize_t read(struct dirent *ent) = 0;
^~
C:\Users\fmukhtarif.platformio\packages\framework-mbed\platform/DirHandle.h:105:16: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined
delete ent;
^~~
C:\Users\fmukhtarif.platformio\packages\framework-mbed\platform/DirHandle.h: In member function 'virtual mbed::dirent mbed::DirHandle::readdir()':
C:\Users\fmukhtarif.platformio\packages\framework-mbed\platform/DirHandle.h:134:30: error: aggregate 'mbed::dirent ent' has incomplete type and cannot be defined
static struct dirent ent;
^~~
In file included from .pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATDirHandle.cpp:9:0:
.pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATDirHandle.h: At global scope:
.pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATDirHandle.h:25:19: error: field 'cur_entry' has incomplete type 'mbed::dirent'
struct dirent cur_entry;
^~~
In file included from .pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATDirHandle.h:8:0,
from .pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATDirHandle.cpp:9:
C:\Users\fmukhtarif.platformio\packages\framework-mbed\platform/DirHandle.h:64:33: note: forward declaration of 'struct mbed::dirent'
virtual ssize_t read(struct dirent ent) = 0;
^~
In file included from srcmd5-400a96bc2b9d9a7d47a9621ebf19020dpp:2:0:
.pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec/SDFileSystem.h:60:22: error: conflicting return type specified for 'virtual uint32_t SDFileSystem::disk_sectors()'
virtual uint32_t disk_sectors();
^~~~
In file included from .pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec/SDFileSystem.h:26:0,
from srcmd5-400a96bc2b9d9a7d47a9621ebf19020dpp:2:
.pio\libdeps\bluepill_f103c8\FatFileSystem_ID385/FATFileSystem.h:55:14: error: overriding 'virtual int mbed::FATFileSystem::disk_sectors()'
virtual int disk_sectors() = 0;
^~~~
srcmd5-400a96bc2b9d9a7d47a9621ebf19020dpp:5:14: error: cannot declare variable 'sd' to be of abstract type 'SDFileSystem'
SDFileSystem sd(PA_5, PA_6, PA_7, PA_8, "sd"); // the pinout on the mbed Cool Components workshop board
^~
In file included from srcmd5-400a96bc2b9d9a7d47a9621ebf19020dpp:2:0:
.pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec/SDFileSystem.h:43:7: note: because the following virtual functions are pure within 'SDFileSystem':
class SDFileSystem : public FATFileSystem {
^~~~~
In file included from C:\Users\fmukhtarif.platformio\packages\framework-mbed/mbed.h:97:0,
from srcmd5-400a96bc2b9d9a7d47a9621ebf19020dpp:1:
C:\Users\fmukhtarif.platformio\packages\framework-mbed/platform/FileSystemHandle.h:56:17: note: virtual int mbed::FileSystemHandle::open(mbed::FileHandle, const char, int)
virtual int open(FileHandle file, const char filename, int flags) = 0;
^
In file included from .pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec/SDFileSystem.h:26:0,
from srcmd5-400a96bc2b9d9a7d47a9621ebf19020dpp:2:
.pio\libdeps\bluepill_f103c8\FatFileSystem_ID385/FATFileSystem.h:52:14: note: virtual int mbed::FATFileSystem::disk_read(char, int)
virtual int disk_read(char buffer, int sector) = 0;
^~~, int)
.pio\libdeps\bluepill_f103c8\FatFileSystem_ID385/FATFileSystem.h:53:14: note: virtual int mbed::FATFileSystem::disk_write(const char
virtual int disk_write(const char buffer, int sector) = 0;
^~~~
* [.pio\build\bluepill_f103c8\lib7fc\FatFileSystem_ID385\FATDirHandle.o] Error 1
[.pio\build\bluepill_f103c8\src\main.o] Error 1
.pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATFileSystem.cpp: In member function 'virtual mbed::FileHandle* mbed::FATFileSystem::open(const char, int)':
.pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATFileSystem.cpp:98:32: error: invalid new-expression of abstract class type 'mbed::FATFileHandle'
return new FATFileHandle(fh);
^
In file included from .pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATFileSystem.cpp:10:0:
.pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATFileHandle.h:13:7: note: because the following virtual functions are pure within 'mbed::FATFileHandle':
class FATFileHandle : public FileHandle {
^~~~~
In file included from C:\Users\fmukhtarif.platformio\packages\framework-mbed/platform/FileSystemHandle.h:22:0,
from C:\Users\fmukhtarif.platformio\packages\framework-mbed\platform/FileSystemLike.h:23,
from .pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATFileSystem.h:22,
from .pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATFileSystem.cpp:5:
C:\Users\fmukhtarif.platformio\packages\framework-mbed/platform/FileHandle.h:87:19: note: virtual off_t mbed::FileHandle::seek(off_t, int)
virtual off_t seek(off_t offset, int whence = SEEK_SET) = 0;
^~mbed::FATFileSystem::opendir(const char)':
.pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATFileSystem.cpp: In member function 'virtual mbed::DirHandle
.pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATFileSystem.cpp:126:32: error: invalid new-expression of abstract class type 'mbed::FATDirHandle'
return new FATDirHandle(dir);
^
In file included from .pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATFileSystem.cpp:11:0:
.pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATDirHandle.h:13:7: note: because the following virtual functions are pure within 'mbed::FATDirHandle':
class FATDirHandle : public DirHandle {
^~~~)
In file included from C:\Users\fmukhtarif.platformio\packages\framework-mbed/platform/FileSystemHandle.h:23:0,
from C:\Users\fmukhtarif.platformio\packages\framework-mbed\platform/FileSystemLike.h:23,
from .pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATFileSystem.h:22,
from .pio\libdeps\bluepill_f103c8\FatFileSystem_ID385\FATFileSystem.cpp:5:
C:\Users\fmukhtarif.platformio\packages\framework-mbed/platform/DirHandle.h:64:21: note: virtual ssize_t mbed::DirHandle::read(dirent
virtual ssize_t read(struct dirent ent) = 0;
^~
C:\Users\fmukhtarif.platformio\packages\framework-mbed/platform/DirHandle.h:70:17: note: virtual int mbed::DirHandle::close()
virtual int close() = 0;
^~~~
C:\Users\fmukhtarif.platformio\packages\framework-mbed/platform/DirHandle.h:77:18: note: virtual void mbed::DirHandle::seek(off_t)
virtual void seek(off_t offset) = 0;
^
C:\Users\fmukhtarif.platformio\packages\framework-mbed/platform/DirHandle.h:83:19: note: virtual off_t mbed::DirHandle::tell()
virtual off_t tell() = 0;
^~
C:\Users\fmukhtarif.platformio\packages\framework-mbed/platform/DirHandle.h:87:18: note: virtual void mbed::DirHandle::rewind()
virtual void rewind() = 0;
^~
* [.pio\build\bluepill_f103c8\lib7fc\FatFileSystem_ID385\FATFileSystem.o] Error 1
In file included from .pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec\SDFileSystem.cpp:115:0:
.pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec\SDFileSystem.h:60:22: error: conflicting return type specified for 'virtual uint32_t SDFileSystem::disk_sectors()'
virtual uint32_t disk_sectors();
^~~~
In file included from .pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec\SDFileSystem.h:26:0,
from .pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec\SDFileSystem.cpp:115:
.pio\libdeps\bluepill_f103c8\FatFileSystem_ID385/FATFileSystem.h:55:14: error: overriding 'virtual int mbed::FATFileSystem::disk_sectors()'
virtual int disk_sectors() = 0;
^~~~~~~~
.pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec\SDFileSystem.cpp: In member function 'int SDFileSystem::initialise_card_v2()':
.pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec\SDFileSystem.cpp:191:19: warning: 'void wait_ms(int)' is deprecated: 'wait_ms' is deprecated in favor of explicit sleep functions. To sleep, 'wait_ms' should be replaced by 'ThisThread::sleep_for' (C++) or 'thread_sleep_for' (C). If you wish to wait (without sleeping), call 'wait_us'. 'wait_us' is safe to call from ISR context. [since mbed-os-5.14] [-Wdeprecated-declarations]
wait_ms(50);
^
In file included from C:\Users\fmukhtarif.platformio\packages\framework-mbed/mbed.h:89:0,
from .pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec\SDFileSystem.h:25,
from .pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec\SDFileSystem.cpp:115:
C:\Users\fmukhtarif.platformio\packages\framework-mbed/platform/mbed_wait_api.h:95:6: note: declared here
void wait_ms(int ms);
^
.pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec\SDFileSystem.cpp: In member function 'uint32_t SDFileSystem::_sd_sectors()':
.pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec\SDFileSystem.cpp:483:122: warning: format '%d' expects argument of type 'int', but argument 3 has type 'uint32_t {aka long unsigned int}' [-Wformat=]
debug_if(SD_DBG, "\n\rSDCard\n\rc_size: %d \n\rcapacity: %ld \n\rsectors: %lld\n\r", c_size, capacity, blocks);
^
.pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec\SDFileSystem.cpp:483:122: warning: format '%lld' expects argument of type 'long long int', but argument 5 has type 'uint32_t {aka long unsigned int}' [-Wformat=]
.pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec\SDFileSystem.cpp:490:134: warning: format '%d' expects argument of type 'int', but argument 3 has type 'uint32_t {aka long unsigned int}' [-Wformat=]
debug_if(SD_DBG, "\n\rSDHC Card \n\rhc_c_size: %d\n\rcapacity: %lld \n\rsectors: %lld\n\r", hc_c_size, blocks512, blocks);
^
.pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec\SDFileSystem.cpp:490:134: warning: format '%lld' expects argument of type 'long long int', but argument 4 has type 'long unsigned int' [-Wformat=]
.pio\libdeps\bluepill_f103c8\SDFileSystem-8db0d3b02cec\SDFileSystem.cpp:490:134: warning: format '%lld' expects argument of type 'long long int', but argument 5 has type 'uint32_t {aka long unsigned int}' [-Wformat=]
* [.pio\build\bluepill_f103c8\libcea\SDFileSystem-8db0d3b02cec\SDFileSystem.o] Error 1
============================================= [FAILED] Took 29.59 seconds =============================================
Also i tried like @laurentS way using build_flags option, but still the error exist.
Here is the platformio.ini
[env:bluepill_f103c8]
platform = ststm32
framework = mbed
board = bluepill_f103c8
; build_flags = -D PIO_FRAMEWORK_MBED_RTOS_PRESENT
lib_deps = FATFileSystem
build_flags = -I C:\Users\fmukhtarif.platformio\packages\toolchain-gccarmnoneeabi\arm-none-eabi\includec++\7.2.1
and the code:
#include "mbed.h"
#include "SDFileSystem.h"
SDFileSystem sd(PA_5, PA_6, PA_7, PA_8, "sd"); // the pinout on the mbed Cool Components workshop board
Serial pc(USBTX, USBRX); // tx, rx
int main() {
pc.printf("Hello World!\n\r");
while(1) {
pc.putc(pc.getc() + 1); // echo input back to terminal
}
}
Most helpful comment
mbed is
c++-based framework. You should use*.cppextension.