Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 8 Replies) [BUG] Weird compilation issue with ArduinoSTL library (C++ templates) (Read 3822 times)
yet-another-average-joe
Junior Member
**
Offline


Posts: 27
Joined: Jul 27th, 2019
[BUG] Weird compilation issue with ArduinoSTL library (C++ templates)
Jul 27th, 2019 at 2:44pm
Print Post  
Hello,

(not sure this is the right place for compilation errors)

This bug report is about code that compiles and works fine in Arduino IDE, but fails in Visual Micro.

Arduino IDE 1.8.9
Visual Studio Community 2017
Visual Micro 1907.16.0 - 16th July 2019

Library : ArduinoSTL : https://github.com/mike-matera/ArduinoSTL

MC : STM32 (STM32F103C8T6 Black Pill)

First of all, the ArduinoSTL library is 'seen" by the Arduino IDE library manager, NOT by the VisualMicro manager... In order to be able to include it in a Visual Micro project, just open the file library.properties, and set the field "architectures" to '*'

Then, download the two archives, TestSTL_1.zip and TestSTL_2.zip. They contain two tiny sketches that will show the problem. The two sketches compile just fine in Arduino IDE, but TestSTL_1 does not compile in Visual Micro.

I suspect some offending gcc command line option in Visual Micro. I wasn't able to find where.
« Last Edit: Jul 27th, 2019 at 2:45pm by yet-another-average-joe »  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: [BUG] Weird compilation issue with ArduinoSTL library (C++ templates)
Reply #1 - Jul 27th, 2019 at 2:57pm
Print Post  
Thanks for the three reports. It would help if you followed the guide in the yellow box and posted the full output with error. Thanks

Some info

1) 

In the Arduino IDE, libraries with invalid architectures will not show on the Libraries menu but will attempt to compile. In this case the first libray it can find that contains a valid header is used.

By coincidence, just published a few hours ago, the next release of Visual Micro attempts to adjust/fix the architectures of libraries where they can possibly be deduced through other logic and finally for libraries that have entirely different architecture spec, an attempt will still be made to compile. You can read more in the work thread in the releases section of this forum. https://www.visualmicro.com/forums/YaBB.pl?board=VS_ARDUINO_EXT_RELEASES

2)

In the current release you did the right thing to correct the invalid lib architectures= in the library.properties. That should then build okay so please provide the build output so we can see more clearly what is being found (or not)

3)

You say the STL is missing from the Visual Micro library manager. We use the same library.index.json that Arduino IDE uses, it is updated/downloaded from the arduino web site when you click  "Check for updates" in the Visual Micro library manager. It's possible the library has only recently been added to the Library Manager by Arduino? I will check the initial .json file that is installed with visual micro to ensure it too is up to date for new users.

« Last Edit: Jul 27th, 2019 at 2:58pm by Tim@Visual Micro »  
Back to top
IP Logged
 
yet-another-average-joe
Junior Member
**
Offline


Posts: 27
Joined: Jul 27th, 2019
Re: [BUG] Weird compilation issue with ArduinoSTL library (C++ templates)
Reply #2 - Jul 27th, 2019 at 3:21pm
Print Post  
Thanks for your answer.

What I meant is that the library does not appear in "add library" (it can be seen in "download and install Arduino library") : there is no "#3) issue". Sorry, english is not my first langage !

Here's the error report (templates are the plague when it comes to debugging  Cheesy
I also opened an issue on Git : https://github.com/mike-matera/ArduinoSTL/issues/33

The errors with the comparison function when compiling TestSTL_1.ino ; no errors with Arduino IDE.

Code (C++)
Select All

TestSTL.ino: 4:14: error: 'Item' was not declared in this scope
Error compiling project sources
Build failed for project 'TestSTL'

TestSTL.ino: 4:20: error: 'item1' was not declared in this scope

TestSTL.ino: 4:27: error: 'Item' was not declared in this scope

TestSTL.ino: 4:33: error: 'item2' was not declared in this scope

TestSTL.ino: 4:38: error: expression list treated as compound expression in initializer [-fpermissive]
TestSTL.ino: In constructor Item::Item(uint32_t, std::string)
TestSTL.ino: 9:11: warning: 'Item::index' will be initialized after [-Wreorder]
   uint32_t index
TestSTL.ino: 8:14: warning:   'std::string Item::str' [-Wreorder]
  std*: string str
TestSTL.ino: 6:2: warning:   when initialized here [-Wreorder]
  Item(uint32_t i, std*: string s): index(i), str(s) {}

TestSTL.ino: In function bool compare(Item&, Item&)

TestSTL.ino: 26:38: error: 'bool compare(Item&, Item&)' redeclared as different kind of symbol
   bool compare(Item& item1, Item& item2)

TestSTL.ino: 4:6: error: previous declaration of 'bool compare

vector:25: In file included from
string:25: from
locale:22: from
ios:22: from
serstream:49: from
ArduinoSTL.h:12: from
TestSTL.ino:1: from
algorithm: In instantiation of void std::stable_sort(RandomAccessIterator, RandomAccessIterator, Compare) [with RandomAccessIterator = Item*; Compare = bool]
algorithm:861: required from void std  sort(RandomAccessIterator, RandomAccessIterator, Compare) [with RandomAccessIterator = Item*; Compare = bool]
TestSTL.ino:49: required from here

algorithm:849: error  comp cannot be used as a function
   if( comp( *temp, *(temp-1) ) ){


 

  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: [BUG] Weird compilation issue with ArduinoSTL library (C++ templates)
Reply #3 - Jul 27th, 2019 at 3:31pm
Print Post  
1)
Quote:
What I meant is that the library does not appear in "add library"


In library manager you can download libraries for ANY platform/architecture. In the Arduino IDE you can add the #includes manually and the library might or might not compile depending on if it it designed for your architecture or not.

Also in the Arduino IDE the menu notice that there is menu "Sketch>Include Library"

Your library does not appear in this menu because the architectures= specification does not allow it. Changing to architectures=* show the library on "Sketch>Include Library" in the Arduino IDE.

This means that a library existing in Library Manager is unrelated to the library being considered valid or not. In fact if you had two libraries installed that contained the same header.h the Arduino IDE would not know which is the correct library, therefore having accurate "architecture=" is quite important.

Arduino IDE allows "invalid" libraries to be compiled, the next release of Visual Micro does the same but with some extra logic.

2)

Pleae provide the information requested in the yellow box at the top of this page as a .txt file. You can email the .txt or click the Reply button here and attach. Please follow the guide and switch on "Verbose" and "Show build properties" as shown in the yellow box.

Thanks
  
Back to top
IP Logged
 
yet-another-average-joe
Junior Member
**
Offline


Posts: 27
Joined: Jul 27th, 2019
Re: [BUG] Weird compilation issue with ArduinoSTL library (C++ templates)
Reply #4 - Jul 27th, 2019 at 3:44pm
Print Post  
I always use these options :

- Verbose
- Add Include
- Warnings for Project
- Warnings for Libraries
- Warnings for Code
- Show Build Properties
- Shared Cache for Cores
- Always Copy Build Output to Intermediate

I copied the output to a txt file :

[EDIT] when downloaded the txt file is not readable !
[EDIT] yes it is (sorry !)
« Last Edit: Jul 27th, 2019 at 3:49pm by yet-another-average-joe »  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: [BUG] Weird compilation issue with ArduinoSTL library (C++ templates)
Reply #5 - Jul 27th, 2019 at 4:04pm
Print Post  
The links you posted are ok, they give the link to the files.

1)
The next release of visual micro now auto adjusts so that libs specified for arduino sam and samd are assumed to be "arm" compatible and the stm boards are also assumed to be arm compatible. So at least other future users will not have to change archtectures=

2)
I think the build issue is that some user types are defined in the .ino and then used as paramaters to methods lower down in the same code. In this case we just need to add prototypes into the correct locations. The same would apply if you move the code to .cpp.

Please attach or email your .ino code and I will try to post example of adding prototypes which are simple like this...

Code (C++)
Select All
//create a user type

struct a ....

//prototype of method using user type
foo(a);

//method using user type
foo(a)
{
}

 



The arduino ide, not so long ago, was improved to make better judgment about the location of the prototypes it inserts into  .ino code in background during build. It's not 100% solution but better than the old way that Visual Micro uses. We will be changing to the new system during the next few months.

An alternative is to always put the creation of user types in .h files (or .cpp) then use them in your .ino code.






  
Back to top
IP Logged
 
yet-another-average-joe
Junior Member
**
Offline


Posts: 27
Joined: Jul 27th, 2019
Re: [BUG] Weird compilation issue with ArduinoSTL library (C++ templates)
Reply #6 - Jul 27th, 2019 at 4:33pm
Print Post  
Not sure I understand what you are asking for : I uploaded sources in the OP...

This being said, I re-wrote the code, as you suggested, with a h and a cpp file. And now it compiles fine with the comprison function. See attachment.

But IMHO, it does not really solve the problem. vMicro should behave like Arduino IDE compiler, shouldn't it ?

This being said, the code that does not works is somewhat stupid. The comparison function HAS to be a member of the objects to be compared.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: [BUG] Weird compilation issue with ArduinoSTL library (C++ templates)
Reply #7 - Jul 27th, 2019 at 4:36pm
Print Post  
Oh yes, sorry I forgot that you uploaded sources initially. I will take a look
  
Back to top
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: [BUG] Weird compilation issue with ArduinoSTL library (C++ templates)
Reply #8 - Jul 27th, 2019 at 5:13pm
Print Post  
Ignore my post about prototypes you are using cpp/h anyway.

I have the same compile issue with STM32 in the Arduino IDE as I do in Visual Micro. The library only appears to work with avr and samd boards.

In the Arduino IDE, please switch on "file>preferences>compile versbose". Then compile the same sketch and post the output as .txt

Thanks
  
Back to top
IP Logged
 
yet-another-average-joe
Junior Member
**
Offline


Posts: 27
Joined: Jul 27th, 2019
Re: [BUG] Weird compilation issue with ArduinoSTL library (C++ templates)
Reply #9 - Jul 27th, 2019 at 5:33pm
Print Post  
(I'm always verbose !)

Please let me know what sources you want me to compile...

TestSTL_1
TestSTL_2
(the OP ones)

or the last sources (with a separate Item class/vector definition)

Discussing with ArduinoSTL author, it appears that ArduinoSTL is not designed for STM32, as you suggested...

I hope I'm not making people losing their time...

Where I live, it's 7:30PM. Saturday. Don't you think you should be having a beer or whatever ? (on my side, the wife will soon be shouting on me...). Weekend is coming, and I will be abroad, with no MC, in a few days (tuesday), for 2 weeks.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: [BUG] Weird compilation issue with ArduinoSTL library (C++ templates)
Reply #10 - Jul 27th, 2019 at 5:38pm
Print Post  
Thanks, yes I agree that library can not work with STM32. 

The confusion is because Arduino allows you to try to build libraries that sometimes are not valid. Visual Micro did not allow this, which in some ways is good but to avoid confusion we will do same as Arduino now Smiley

Enjoy your beer.

« Last Edit: Jul 27th, 2019 at 5:38pm by Tim@Visual Micro »  
Back to top
IP Logged
 
yet-another-average-joe
Junior Member
**
Offline


Posts: 27
Joined: Jul 27th, 2019
Re: [BUG] Weird compilation issue with ArduinoSTL library (C++ templates)
Reply #11 - Jul 27th, 2019 at 5:47pm
Print Post  
Great !
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: [BUG] Weird compilation issue with ArduinoSTL library (C++ templates)
Reply #12 - Aug 4th, 2019 at 12:18pm
Print Post  
There have been a lot of imporvements to shared libraries and library resolution in 1908.3+

https://www.visualmicro.com/forums/YaBB.pl?board=VS_ARDUINO_EXT_RELEASES
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint