Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::vector unable to build in empty project #197

Open
JesseSwildens opened this issue Aug 18, 2022 · 0 comments
Open

std::vector unable to build in empty project #197

JesseSwildens opened this issue Aug 18, 2022 · 0 comments

Comments

@JesseSwildens
Copy link

Processing sodaq_explorer (platform: atmelsam; board: sodaq_explorer; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/sodaq_explorer.html
PLATFORM: Atmel SAM (7.1.0) > SODAQ ExpLoRer
HARDWARE: SAMD21J18A 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink)
PACKAGES:
 - framework-arduino-samd-sodaq @ 1.8.6
 - framework-cmsis @ 1.40500.0 (4.5.0)
 - framework-cmsis-atmel @ 1.2.2
 - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 16 compatible libraries
Scanning dependencies...     
No dependencies
Building in release mode
Compiling .pio\build\sodaq_explorer\src\main.cpp.o
Compiling .pio\build\sodaq_explorer\FrameworkArduinoVariant\variant.cpp.o
Compiling .pio\build\sodaq_explorer\FrameworkArduino\IPAddress.cpp.o
Compiling .pio\build\sodaq_explorer\FrameworkArduino\Print.cpp.o    
Compiling .pio\build\sodaq_explorer\FrameworkArduino\Reset.cpp.o
Compiling .pio\build\sodaq_explorer\FrameworkArduino\SERCOM.cpp.o
Compiling .pio\build\sodaq_explorer\FrameworkArduino\Stream.cpp.o
Compiling .pio\build\sodaq_explorer\FrameworkArduino\Tone.cpp.o  
Compiling .pio\build\sodaq_explorer\FrameworkArduino\USB\CDC.cpp.o
Compiling .pio\build\sodaq_explorer\FrameworkArduino\USB\PluggableUSB.cpp.o
Compiling .pio\build\sodaq_explorer\FrameworkArduino\USB\USBCore.cpp.o
Compiling .pio\build\sodaq_explorer\FrameworkArduino\USB\samd21_host.c.o
In file included from c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\vector:60:0,
                 from src\main.cpp:2:
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                        ^
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:265:56: error: macro "max" passed 3 arguments, but takes just 2
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                        ^
In file included from src\main.cpp:1:0:
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:195:5: error: expected unqualified-id before 'const'
     min(const _Tp& __a, const _Tp& __b)
     ^
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:195:5: error: expected ')' before 'const'
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:195:5: error: expected ')' before 'const'
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:195:5: error: expected initializer before 'const'
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:219:5: error: expected unqualified-id before 'const'
     max(const _Tp& __a, const _Tp& __b)
     ^
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:219:5: error: expected ')' before 'const'
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:219:5: error: expected ')' before 'const'
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:219:5: error: expected initializer before 'const'
In file included from c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\vector:60:0,
                 from src\main.cpp:2:
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:246:7: error: expected primary-expression before 'if'
       if (__comp(__b, __a))
       ^~
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:246:7: error: expected '}' before 'if'
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:246:7: error: expected ';' before 'if'
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:248:7: error: expected unqualified-id before 'return'
       return __a;
       ^~~~~~
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:268:7: error: expected primary-expression before 'if'
       if (__comp(__a, __b))
       ^~
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:268:7: error: expected '}' before 'if'
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:268:7: error: expected ';' before 'if'
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:270:7: error: expected unqualified-id before 'return'
       return __a;
       ^~~~~~
c:\users\jesse\.platformio\packages\[email protected]\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:271:5: error: expected declaration before '}' token
     }
     ^
*** [.pio\build\sodaq_explorer\src\main.cpp.o] Error 1

Incorrectly working:

#include <Arduino.h>
#include <vector>

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}

The solution:

#include <vector>
#include <Arduino.h>


void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}

In the Arduino.h file are a number of overlapping functions that are in conflict with the include vector. The one in these errors were the min() and max() defines. Where the C++ compiler has an overloading of these functions and defaults to the defines. This creates a problem for when these try to create a template for further code.

The solution is to include the vector and other C++ files before the #include <Arduino.h>.
This could pose a issue when people start to code their project and overlook this. So maybe something for the wiki documentation or this issue in github. In the case that people have the same issue in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant