VS Arduino
Visual Micro >> Installation & Troubleshooting >> <vector><string> compilation problem
https://www.visualmicro.com/forums/YaBB.pl?num=1599049576

Message started by elotn on Sep 2nd, 2020 at 12:26pm

Title: <vector><string> compilation problem
Post by elotn on Sep 2nd, 2020 at 12:26pm
I have problem with compilation when I'm returning <vector><string>. I made some tests and the same code compile on PlatformIO and on Arduino. It's easy to replicate problem with VisualMicro. I'm using:
Visual Studio Community 2019 16.7.2
VisualMicro PRO 2020.708.7
Arduino 1.8.13
board is OLIMEX ESP32-EVB
For me it looks like wrong vector and string is used from external dependencies. There is ArduinoSTL instead of esp.

ERROR:
VectorTest1.ino: 8:1: error: invalid use of template-name 'std::vector' without an argument list
   vector<string> test = split("test test test", " ")

CODE FOR REPLICATE PROBLEM:
#include <vector>
#include <string>

using namespace std;
vector<string> split(const string& str, const string& delim);
void setup() {

    vector<string> test = split("test test test", " ");
}

void loop() {
    // put your main code here, to run repeatedly:
}
vector<string> split(const string& str, const string& delim)
{
    vector<string> tokens;
    return tokens;
}

Please find build log and solution in attachment. Thank you for any suggestions.

https://www.visualmicro.com/forums/YaBB.pl?action=downloadfile;file=vectortest.zip ( 18133 KB | 2 Downloads )

Title: Re: <vector><string> compilation problem
Post by Simon Hopkinson on Sep 2nd, 2020 at 1:32pm
Thanks for the detailed information and example, we are currently investigating this issue and will update when there is a workaround or fix available.


Title: Re: <vector><string> compilation problem
Post by Simon Hopkinson on Sep 2nd, 2020 at 6:35pm
In the latest forum release (20.07.08.13) this issue should now be resolved, and it can be downloaded from the top of the below board:
https://www.visualmicro.com/forums/YaBB.pl?board=VS_ARDUINO_EXT_RELEASES

If you haven't installed one of the forum releases before, further help is below:
Documentation - See Section 2. Install Visual Micro
Walkthrough Video on YouTube

Let us know if you encounter any further issues, and thanks again for the clear reporting.

Title: Re: <vector><string> compilation problem
Post by elotn on Sep 3rd, 2020 at 9:35am
Thank you for the fast response. The main problem is solved in 20.07.08.13. I can use vector of strings as a return type. The other minor issue is that 'using' doesn't work?

When I include
#include <vector>
#include <string>
and use:
using std::vector;
using std::string;
or using namespace std;
and
CODE:
vector<std::string> split(const std::string& str, const std::string& delim)
{
    std::vector<std::string> tokens;
    return tokens;
}


VectorTest1.ino: 7:1: error: 'vector' does not name a type
CODE:
std::vector<std::string> split(const std::string& str, const std::string& delim)
{
    std::vector<std::string> tokens;
    return tokens;
}


Compilation ok, no error

The same for string
CODE:
std::vector<string> split(const std::string& str, const std::string& delim)
{
    std::vector<std::string> tokens;
    return tokens;
}


ERROR:
VectorTest1.ino: 7:13: error: 'string' was not declared in this scope
   vector<string> split(const string& str, const string& delim)
VectorTest1.ino:7: note  suggested alternatives

string:39: In file included from
random:40: from
stl_algo.h:66: from
algorithm:62: from
arduino.h:142: from
VectorTest1.ino: from
Error compiling .ino project source
stringfwd.h:74: note    std  __cxx11  string
Debug build failed for project 'VectorTest1'
   typedef basic_string<char>    string
stringfwd.h:74: note    std  __cxx11  string

VectorTest1.ino: 7:19: error: template argument 1 is invalid
   vector<string> split(const string& str, const string& delim)

VectorTest1.ino: 7:19: error: template argument 2 is invalid

VectorTest1.ino: 11:60: error: ambiguating new declaration of 'std::vector<std::__cxx11::basic_string<char> > split(const string&, const string&)
VectorTest1.ino:7: note  old declaration int split(const string&, const string&)
   vector<string> split(const string& str, const string& delim)

VectorTest1.ino: In function void setup()

VectorTest1.ino: 14:28: error: conversion from 'int' to non-scalar type 'std::vector<std::__cxx11::basic_string<char> >' requested
   put your main code here, to run repeatedly

VectorTest1.ino: In function std::vector<std::__cxx11::basic_string<char> > split(const string&, const string&)

VectorTest1.ino: 20:75: error: ambiguating new declaration of 'std::vector<std::__cxx11::basic_string<char> > split(const string&, const string&)
VectorTest1.ino:7: note  old declaration int split(const string&, const string&)
   vector<string> split(const string& str, const string& delim)

Title: Re: <vector><string> compilation problem
Post by Simon Hopkinson on Sep 3rd, 2020 at 10:10am
Would it be possible to re-send the example solution and fresh build log (also enable the vMicro > Compile > Show Build properties as shown in the yellow box at the top)?

I'm struggling to replicate the latest issue on my machine at present, so hopefully the additional information will reveal something I'm missing.

Title: Re: <vector><string> compilation problem
Post by elotn on Sep 3rd, 2020 at 10:34am
Sure, please find build log with enabled Build properties and example solution in attachment. I hope it helps.
https://www.visualmicro.com/forums/YaBB.pl?action=downloadfile;file=vectortest_001.zip ( 24311 KB | 3 Downloads )

Title: Re: <vector><string> compilation problem
Post by Visual Micro on Sep 3rd, 2020 at 10:00pm
Thanks for the output. The output shows that the serial usb deugger is enabled. Please switch the tool bar from Debug to Release to avoid use of the Serial object (which your code prevents from working)

Thank you

VS Arduino » Powered by YaBB 2.6.12!
YaBB Forum Software © 2000-2024. All Rights Reserved.