Unable to build with libraries (sublime text + platformio)

Hi all,

I feel like I’m not the first with this problem, but I can’t get anything to work. Trying to switch from Arduino IDE to Sublime Text, and I run into the same thing either way. FWIW, I’m trying sublime text after failing at getting platformio to work within Emacs. So here I am. Here’s the bones of a sketch, trying to build for Teensy 3.6:

#include <TeensyStep.h>
#include <TimeLib.h>
#include <SD.h>
#include <SPI.h>


void setup() {
}

void loop() {
}

…Simple enough, right? One would think. It also doesn’t work if I #include <Arduino.h>. Here’s my platformio.ini:

[env:teensy36]
platform = teensy
board = teensy36
framework = arduino
lib_extra_dirs = /Users/sam/code/arduino/libraries
lib_deps = 
    luni64/TeensyStep @ ^2.1
    paulstoffregen/Time @ ^1.6.1
    arduino-libraries/SD @ ^1.2.4

When I try to build, I get this pile of garbage. Looks to my (experienced but non-expert c++) eye like it can’t even find a bunch of basic C++ utilities. I understand platformio has this whole philosophy about libraries, but… wouldn’t it be easier to just use the system installed libraries like the arduino / teensyduino IDE, which has no problems with this?

Summary
[ Deviot 2.2.2 ] Starting...
Processing teensy36 (platform: teensy; board: teensy36; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy36.html
PLATFORM: Teensy (4.13.1) > Teensy 3.6
HARDWARE: MK66FX1M0 180MHz, 256KB RAM, 1MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES: 
 - framework-arduinoteensy 1.154.0 (1.54) 
 - toolchain-gccarmnoneeabi 1.50401.190816 (5.4.1)
Converting full_build_v3.ino
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 118 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <TeensyStep> 2.1.0
|   |-- <StandardCplusplus>
|-- <Time> 1.6.1
|-- <SD> 1.2.4
|   |-- <SPI> 1.0
|-- <OneWire> 2.3.5
|-- <SPI> 1.0
Building in release mode
Compiling .pio/build/teensy36/src/full_build_v3.ino.cpp.o
Compiling .pio/build/teensy36/lib584/StandardCplusplus/algorithm.cpp.o
Compiling .pio/build/teensy36/lib584/StandardCplusplus/associative_base.cpp.o
Compiling .pio/build/teensy36/lib584/StandardCplusplus/bitset.cpp.o
Compiling .pio/build/teensy36/lib584/StandardCplusplus/char_traits.cpp.o
Compiling .pio/build/teensy36/lib584/StandardCplusplus/complex.cpp.o
Compiling .pio/build/teensy36/lib584/StandardCplusplus/del_op.cpp.o
Compiling .pio/build/teensy36/lib584/StandardCplusplus/del_opnt.cpp.o
Compiling .pio/build/teensy36/lib584/StandardCplusplus/del_opv.cpp.o
Compiling .pio/build/teensy36/lib584/StandardCplusplus/del_opvnt.cpp.o
Compiling .pio/build/teensy36/lib584/StandardCplusplus/deque.cpp.o
Compiling .pio/build/teensy36/lib584/StandardCplusplus/eh_alloc.cpp.o
In file included from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/WProgram.h:45:0,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/Arduino.h:6,
                 from /var/folders/w7/h4832m4j00j3ml2f0k0761s80000gn/T/tmpxed1td61:1:
/Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:48:76: error: 'enable_if' in namespace 'std' does not name a template type
 long map(T _x, A _in_min, B _in_max, C _out_min, D _out_max, typename std::enable_if<std::is_integral<T>::value >::type* = 0)
                                                                            ^
/Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:48:85: error: expected ',' or '...' before '<' token
 long map(T _x, A _in_min, B _in_max, C _out_min, D _out_max, typename std::enable_if<std::is_integral<T>::value >::type* = 0)
                                                                                     ^
/Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:84:68: error: 'enable_if' in namespace 'std' does not name a template type
 T map(T x, A in_min, B in_max, C out_min, D out_max, typename std::enable_if<std::is_floating_point<T>::value >::type* = 0)
                                                                    ^
/Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:84:77: error: expected ',' or '...' before '<' token
 T map(T x, A in_min, B in_max, C out_min, D out_max, typename std::enable_if<std::is_floating_point<T>::value >::type* = 0)
                                                                             ^
In file included from /Users/sam/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/5.4.1/utility:69:0,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:89,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/WProgram.h:45,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/Arduino.h:6,
                 from /var/folders/w7/h4832m4j00j3ml2f0k0761s80000gn/T/tmpxed1td61:1:
/Users/sam/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/5.4.1/bits/stl_relops.h:87:7: error: redefinition of 'template<class _Tp> bool std::rel_ops::operator!=(const _Tp&, const _Tp&)'
       operator!=(const _Tp& __x, const _Tp& __y)
       ^

**[ lines omitted for brevity ]**

In file included from /Users/sam/code/arduino/libraries/StandardCplusplus/memory:24:0,
                 from /Users/sam/code/arduino/libraries/StandardCplusplus/type_traits:22,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:45,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/WProgram.h:45,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/Arduino.h:6,
                 from /var/folders/w7/h4832m4j00j3ml2f0k0761s80000gn/T/tmpxed1td61:1:
/Users/sam/code/arduino/libraries/StandardCplusplus/utility.h:40:33: note: 'template<class T> bool std::rel_ops::operator<=(const T&, const T&)' previously declared here
   template<class T> inline bool operator<=(const T& x, const T& y){
                                 ^
In file included from /Users/sam/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/5.4.1/utility:69:0,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:89,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/WProgram.h:45,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/Arduino.h:6,
                 from /var/folders/w7/h4832m4j00j3ml2f0k0761s80000gn/T/tmpxed1td61:1:
/Users/sam/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/5.4.1/bits/stl_relops.h:126:7: error: redefinition of 'template<class _Tp> bool std::rel_ops::operator>=(const _Tp&, const _Tp&)'
       operator>=(const _Tp& __x, const _Tp& __y)
       ^
In file included from /Users/sam/code/arduino/libraries/StandardCplusplus/memory:24:0,
                 from /Users/sam/code/arduino/libraries/StandardCplusplus/type_traits:22,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:45,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/WProgram.h:45,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/Arduino.h:6,
                 from /var/folders/w7/h4832m4j00j3ml2f0k0761s80000gn/T/tmpxed1td61:1:
/Users/sam/code/arduino/libraries/StandardCplusplus/utility.h:44:33: note: 'template<class T> bool std::rel_ops::operator>=(const T&, const T&)' previously declared here
   template<class T> inline bool operator>=(const T& x, const T& y){
                                 ^> 
**[ lines omitted for brevity ]**

/Users/sam/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/5.4.1/bits/move.h:178:55: error: expected primary-expression before ',' token
     noexcept(__and_<is_nothrow_move_constructible<_Tp>,
                                                       ^
/Users/sam/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/5.4.1/bits/move.h:178:55: error: expected ')' before ',' token
/Users/sam/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/5.4.1/bits/move.h:178:55: error: expected ';' before ',' token
In file included from /Users/sam/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/5.4.1/utility:70:0,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:89,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/WProgram.h:45,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/Arduino.h:6,
                 from /var/folders/w7/h4832m4j00j3ml2f0k0761s80000gn/T/tmpxed1td61:1:
/Users/sam/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/5.4.1/bits/stl_pair.h:96:12: error: redefinition of 'struct std::pair<T1, T2>'
     struct pair
            ^
In file included from /Users/sam/code/arduino/libraries/StandardCplusplus/memory:24:0,
                 from /Users/sam/code/arduino/libraries/StandardCplusplus/type_traits:22,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:45,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/WProgram.h:45,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/Arduino.h:6,
                 from /var/folders/w7/h4832m4j00j3ml2f0k0761s80000gn/T/tmpxed1td61:1:
/Users/sam/code/arduino/libraries/StandardCplusplus/utility.h:49:51: error: previous definition of 'struct std::pair<T1, T2>'
  template <class T1, class T2> struct _UCXXEXPORT pair {
                                                   ^
In file included from /Users/sam/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/5.4.1/utility:70:0,> 
**[ lines omitted for brevity ]**

                 from /var/folders/w7/h4832m4j00j3ml2f0k0761s80000gn/T/tmpxed1td61:1:
/Users/sam/code/arduino/libraries/StandardCplusplus/utility.h:70:37: note: 'template<class T1, class T2> bool std::operator>(const std::pair<T1, T2>&, const std::pair<T1, T2>&)' previously declared here
  template <class T1, class T2> bool operator> (const pair<T1,T2>& x, const pair<T1,T2>& y){
                                     ^
In file included from /Users/sam/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/5.4.1/utility:70:0,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:89,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/WProgram.h:45,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/Arduino.h:6,
                 from /var/folders/w7/h4832m4j00j3ml2f0k0761s80000gn/T/tmpxed1td61:1:
/Users/sam/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/5.4.1/bits/stl_pair.h:239:5: error: redefinition of 'template<class _T1, class _T2> constexpr bool std::operator<=(const std::pair<T1, T2>&, const std::pair<T1, T2>&)'
     operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
     ^
In file included from /Users/sam/code/arduino/libraries/StandardCplusplus/memory:24:0,
                 from /Users/sam/code/arduino/libraries/StandardCplusplus/type_traits:22,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:45,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/WProgram.h:45,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/Arduino.h:6,
                 from /var/folders/w7/h4832m4j00j3ml2f0k0761s80000gn/T/tmpxed1td61:1:
/Users/sam/code/arduino/libraries/StandardCplusplus/utility.h:76:37: note: 'template<class T1, class T2> bool std::operator<=(const std::pair<T1, T2>&, const std::pair<T1, T2>&)' previously declared here
  template <class T1, class T2> bool operator<=(const pair<T1,T2>& x, const pair<T1,T2>& y){
                                     ^
In file included from /Users/sam/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/5.4.1/utility:70:0,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:89,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/WProgram.h:45,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/Arduino.h:6,> 
**[ lines omitted for brevity ]**

                                        ^
/Users/sam/code/arduino/libraries/StandardCplusplus/unwind-cxx.h:181:39: error: ISO C++ forbids casting to an array type '_Unwind_Exception_Class {aka char [8]}'
      << 8 | (_Unwind_Exception_Class) '+')
                                       ^
/Users/sam/code/arduino/libraries/StandardCplusplus/unwind-cxx.h:182:38: error: ISO C++ forbids casting to an array type '_Unwind_Exception_Class {aka char [8]}'
     << 8 | (_Unwind_Exception_Class) '+')
                                      ^
/Users/sam/code/arduino/libraries/StandardCplusplus/unwind-cxx.h:183:37: error: ISO C++ forbids casting to an array type '_Unwind_Exception_Class {aka char [8]}'
    << 8 | (_Unwind_Exception_Class) '\0');
                                     ^
*** [.pio/build/teensy36/lib584/StandardCplusplus/eh_alloc.cpp.o] Error 1
In file included from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/WProgram.h:45:0,
                 from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/Arduino.h:6,
                 from /var/folders/w7/h4832m4j00j3ml2f0k0761s80000gn/T/tmpxed1td61:1:
.pio/libdeps/teensy36/TeensyStep/src/Stepper.h: In static member function 'static bool TeensyStep::Stepper::cmpVmin(const TeensyStep::Stepper*, const TeensyStep::Stepper*)':
/Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:141:16: error: expected unqualified-id before '(' token
 #define abs(x) ({ \
                ^
>
**[ abbreviated but it's more of the same ]**

========================== [FAILED] Took 1.24 seconds ==========================

[Thu Sep 16 13:27:38 2021]

As shown be the log you posted, the StandardCplusplus library that you have installed in your

folder is interfering with the build. PlatformIO is picking up includes to standard C++ library headers as a reference to this library.

Instead of doing lib_extra_dirs add-all-my-libs stuff, it’s better to do all library dependency management via lib_deps and the library registry. You already have the correct lib_deps to build stand-alone, so just remove the lib_extra_dirs line.

Alternatively of course, remove the StandardCpluspluls library from your library folder, or use lib_ignore (in every project that uses C++ and picks up this interfering library).

Huh. I figured it wouldn’t care about libraries that were unreferenced in the main sketch… clearly I understand less than I thought about how this linking happens.

Thanks for the tip, that cleared the error. On to the next error!

From the dependency graph you can see which libraries and dependencies of these libraries were detected by PlatformIO. It’s seeing the TeensyStep library as being dependent on a header exposed by the StandardCplusplus library.

Ah so. Interesting!

I’ve tried to copy this same structure into an existing project (that’s not just empty setup() and loop()), and I’m running into a strange one. When I build, it adds the lib_extra_dirs line back into platformio.ini, then fails for the same reason. If I delete the line, save, then build again, it comes back. Same deal if I “delete” the option from the PlatformIO home web GUI. Any pointers?

(Thanks for your help, by the way – and apologies for the saltiness on the original post… I know it’ll pay off, but it’s been frustrating to try and switch from the arduino IDE which hides away most of this stuff).

update: it gets a bit farther if I do pio run instead of compiling from within sublime text – in that case, I get error: 'BUILTIN_SDCARD' was not declared in this scope. Figured this was because it’s not using the right SD library, so I cloned the correct one into the local libs directory, but then I get:

In file included from /Users/sam/code/arduino/fountain/sam/full_build_v3_pio/src/full_build_v3.ino:27:0:
lib/SD/src/SD.h:54:1: error: expected class-name before '{' token
 {
 ^
lib/SD/src/SD.h: In member function 'virtual File SDFile::openNextFile(uint8_t)':
lib/SD/src/SD.h:126:41: error: no matching function for call to 'File::File(SDFile*)'
   if (file) return File(new SDFile(file));

Any thoughts?

My bad, I was actually wrong about you using the correct libraries. The line

should not be in lib_deps because that’s the wrong SD library. The teensy Arduino core comes with its own SD library (see C:\Users\<user>\.platformio\packages\framework-arduinoteensy\libraries\SD).

After deleting that line you should also remove the entire .pio file where old build files & libraries are stored.

I’ve never seen that behavior occuring. Wondering if it’s something that the IDE does, especially when it doesn’t do that with pio run.

Hi @maxgerhardt,

I suffered with exactly that problem a few times using Atom as my editor. I never figured out why it happened unfortunately, but changes I made before compiling were reverted back into the ini file and I saw all the same errors again.

If I remember correctly, I ended up in with a nuclear option:

  • build clean;
  • delete .pio;
  • build.

Sometimes it worked, sometimes not. In the end I think I ended up creating a new project directory, copying my files across and recreating the ini file manually.

I have not had this problem for a while now. But I tend to use the command line or VSCode – I got fed up with Atom being so slow on my aging laptop.

Cheers,
Norm.

@normandunbar good call. Deleting .pio/, then clean, then build, fixed the mysterious reappearing line.

Now I’m back to getting errors with… looks like Arduino.h?

In file included from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/WProgram.h:45:0,
             from /Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/Arduino.h:6,
             from /var/folders/w7/h4832m4j00j3ml2f0k0761s80000gn/T/tmpgj8rj1_h:1:
/Users/sam/.platformio/packages/framework-arduinoteensy/cores/teensy3/wiring.h:48:76: error:   'enable_if' in namespace 'std' does not name a template type
long map(T _x, A _in_min, B _in_max, C _out_min, D _out_max, typename std::enable_if<std::is_integral<T>::value >::type* = 0)

My Dependency graph now looks like:

Dependency Graph
|-- <TeensyStep> 2.1.0
|   |-- <StandardCplusplus>
|-- <Time> 1.6.1
|-- <SD> 2.0.0
|   |-- <SdFat> 2.0.5-beta.1
|   |   |-- <SPI> 1.0
|-- <SPI> 1.0

That SD library is the correct one, afaik. v. 2.0.0 of Paul Stoffregen’s wrapper around SdFat. I don’t mind using the command line, but that’s not really much better than tabbing back over to Arduino to compile + upload. I’d love to see this upload straight from an IDE!

VSCode is the recommended IDE.

The StandardCplusplus library is still messing with your builds as before.

if it’s the case that it only really works in VSCode, this seems… misleading:

Having support for many many IDEs and having two IDEs where main development happens (VSCode + CLion) and is recommended because it makes the most sense for a tool is not contradictive in my eyes.

That is directly stated in the docs too.

We highly recommend to use the next native integrations for: