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
Normal Topic Template compilation issue (Read 3727 times)
renaud.bedard
Newbies
*
Offline


Posts: 3
Joined: Jul 4th, 2014
Template compilation issue
Jul 4th, 2014 at 3:58pm
Print Post  
Hi,

I just started using Visual Micro for VS2010 with an Arduino Leonardo, and I'm having issues compiling a class with templates.

This class and usage causes a 
Code
Select All
Compiling 'sketch' for 'Arduino Leonardo'
sketch.cpp.o:In function `loop'
sketch.ino:update()'
Error creating .elf
 



Code (C++)
Select All
// Container.h
template <int N>
class Container
{
private:
    bool activeMask[N];
public:
    void update();
};

// Container.cpp
template <int N>
void Container<N>::update()
{
}

// sketch.ino
Container<1> container;

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    container.update();
}
 



Commenting out the "container.update()" makes the compilation work fine.

Any idea?
Thanks!
  
Back to top
 
IP Logged
 
renaud.bedard
Newbies
*
Offline


Posts: 3
Joined: Jul 4th, 2014
Re: Template compilation issue
Reply #1 - Jul 4th, 2014 at 4:43pm
Print Post  
Verbose log :

Code
Select All
Compiling 'sketch' for 'Arduino Leonardo'
Build folder: file:///C:/Users/Renaud/AppData/Local/VMicro/Arduino/Builds/sketch/leonardo
Summary: Header=1 Prototypes=3 Imports=0
Additional Defines: VISUALMICRO_COMPILER_VER=1;
Architecture Tools: C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\
GCC: 4.3.2
Sketchbook: file:///C:/Users/Renaud/Documents/Arduino
Include Path 'C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino'
Include Path 'C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\leonardo'
Include Path 'C:\Program Files (x86)\Arduino\libraries'
Include Path 'C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries'
Include Path 'C:\Users\Renaud\Documents\Arduino\libraries'
"C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++" -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 -DUSB_MANUFACTURER= -DUSB_PRODUCT="\"Arduino Leonardo\"" -I"C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" -I"C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\leonardo" -I"C:\Program Files (x86)\Arduino\libraries" -I"C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries" -I"C:\Program Files (x86)\Visual Micro\Visual Micro for Arduino\Micro Platforms\default\debuggers" -I"C:\Users\Renaud\Documents\Arduino\libraries" pp" -o pp.o" -DVISUALMICRO_COMPILER_VER=1
"C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++" -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 -DUSB_MANUFACTURER= -DUSB_PRODUCT="\"Arduino Leonardo\"" -I"C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" -I"C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\leonardo" -I"C:\Program Files (x86)\Arduino\libraries" -I"C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries" -I"C:\Program Files (x86)\Visual Micro\Visual Micro for Arduino\Micro Platforms\default\debuggers" -I"C:\Users\Renaud\Documents\Arduino\libraries"  -o o" -DVISUALMICRO_COMPILER_VER=1
"C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-gcc" -Os -Wl,--gc-sections -mmcu=atmega32u4 -o  pp.o" o" "C:\Users\Renaud\AppData\Local\VMicro\Arduino\Builds\sketch\leonardo/core.a" "-LC:\Users\Renaud\AppData\Local\VMicro\Arduino\Builds\sketch\leonardo" -lm
sketch.cpp.o:In function `loop'
sketch.ino:update()'
Error creating .elf
 

« Last Edit: Jul 4th, 2014 at 4:43pm by renaud.bedard »  
Back to top
 
IP Logged
 
renaud.bedard
Newbies
*
Offline


Posts: 3
Joined: Jul 4th, 2014
Re: Template compilation issue
Reply #2 - Jul 4th, 2014 at 5:04pm
Print Post  
Thanks for the response!

I can't really do an instantiation at the bottom because the template argument is meant to be defined at the call-site.

However I realized that it's just a template instantiation problem... if the implementation is not available at the call-site, it fails at link time : http://stackoverflow.com/questions/1639797/template-issue-causes-linker-error-c

By putting the implementation in the .h file (instead of a .cpp file) like Arduino libraries like QueueList does, it works fine.

Thanks though!
« Last Edit: Jul 4th, 2014 at 5:05pm by renaud.bedard »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Template compilation issue
Reply #3 - Jul 4th, 2014 at 5:09pm
Print Post  
Yes I just worked that out thanks  Smiley

I notice the compiler error message isn't quite right so we will correct that.
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint