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) How to use Assembler together with C++ / Linker problem (Read 9798 times)
Hanilein
Newbies
*
Offline


Posts: 6
Location: New Zealand
Joined: Nov 26th, 2014
How to use Assembler together with C++ / Linker problem
Nov 26th, 2014 at 8:23am
Print Post  
Hello Community,

I'm using Atmel Studio 6.2 and Visual Micro. I want to mix Assembler with C++ using a .S-file.
Unfortunately I have a linker problem, the output of the compiler run creates an undefined reference to `foobar' error.

Following tips from the internet I created a .S file containing a function pulling some port pins:

Code
Select All
 #include <avr/io.h>

 .section .text
 .global foobar
  foobar:

 start:
	cbi		0x05,4
	sbi		0x05,4

	sbi		0x05,5
	sbi		0x05,3
	nop
	cbi		0x05,5
	cbi		0x05,3
	rjmp	start 



My .ino - file contains the declaration line

Code
Select All
extern "C" {void foobar(void);} 



and in the setup() function I call my function

Code
Select All
	foobar(); 

 

However, when I try to compile the outcome is 

Code
Select All
Compiling 'LCD7SEG' for 'Arduino Uno'
LCD7SEG.cpp.o:In function `setup'
LCD7SEG.ino:undefined reference to `foobar'
Error creating .elf 



I tried to put the assembler source code in the sketchbook\libraries subfolder, in the folder where the ino file lives, I added it as a library or just as a source code to the solution explorer - it does not work.

To me it looks like the system just not assembles the source code - how can I make that happen (and tell the linker to use the .O file)?

Thank you very much






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


Posts: 12186
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to use Assembler together with C++ / Linker problem
Reply #1 - Nov 26th, 2014 at 2:04pm
Print Post  
Hi,

If it also fails in the arduino ide then the question is about arduino and not about a visual micro problem. in that case please use arduino.cc forum for this type of question

Thanks
  
Back to top
IP Logged
 
Hanilein
Newbies
*
Offline


Posts: 6
Location: New Zealand
Joined: Nov 26th, 2014
Re: How to use Assembler together with C++ / Linker problem
Reply #2 - Nov 26th, 2014 at 7:29pm
Print Post  
Hi, 

it works picture perfect with the Arduino IDE, just triple checked it.

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


Posts: 12186
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to use Assembler together with C++ / Linker problem
Reply #3 - Nov 26th, 2014 at 10:55pm
Print Post  
Thanks, we haven't done a lot of testing with .s files. It sounds like we are missing them during the copy process of the build. We should be able to fix that quite easily.

In the arduino ide please switch on file>preferences>verbose compile then build and email the output

With Visual Micro please tick "tools>visual micro>verbose messages", then click "build>clean solution" and then build and email the output

email address info [at] visualmicro.com

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


Posts: 12186
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to use Assembler together with C++ / Linker problem
Reply #4 - Nov 27th, 2014 at 4:39am
Print Post  
Thanks for the files which show that Visual Micro is unable to find or detect the Send595 library.

LCD7SEG.ino:29:21: warning: Send595.h: No such file or directory

Questions

Can you see the Send595 library on menu "project>add/import sketch library>user"?

Are you using the visual micro version from the atmel gallery? you can see tools>options>visual micro>version if you are not sure. The current version on visual micro is a little more recent and will show 1407.10 and minor version 10

If you are not on the latest visual micro release then please close atmel studio and run the visual micro installer from visualmicro.com

If you are on the latest release and the issue remains then please switch on "tools>options>visual micro>user interface>trace". Then restart atmel studio and email the trace that appears in the output window.

Thanks again


« Last Edit: Nov 27th, 2014 at 4:40am by Tim@Visual Micro »  
Back to top
IP Logged
 
Hanilein
Newbies
*
Offline


Posts: 6
Location: New Zealand
Joined: Nov 26th, 2014
Re: How to use Assembler together with C++ / Linker problem
Reply #5 - Nov 27th, 2014 at 6:48am
Print Post  
Thanks Tim,

To answer your questions:


Quote:
Can you see the Send595 library on menu "project>add/import sketch library>user"?

Yes

Quote:
Are you using the visual micro version from the atmel gallery? you can see tools>options>visual micro>version if you are not sure. The current version on visual micro is a little more recent and will show 1407.10 and minor version 10

It was 1407.10 minor 0, it is 1407.10 minor 10 now.

Quote:

If you are not on the latest visual micro release then please close atmel studio and run the visual micro installer from visualmicro.com

Jupp, done.

Quote:
If you are on the latest release and the issue remains then please switch on "tools>options>visual micro>user interface>trace". Then restart atmel studio and email the trace that appears in the output window.


All right - the issue remains, I just sent the trace in an email.
That's really an interesting problem - Thank you very much for your help.


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


Posts: 12186
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to use Assembler together with C++ / Linker problem
Reply #6 - Nov 27th, 2014 at 4:19pm
Print Post  
Hi,

Thanks for the trace which looks okay.

Yes it is an interesting problem. 

Can you please zip and email your library folder called Serial595 and also your sketch code. The codes will be kept private and deleted after the test.

Thanks
  
Back to top
IP Logged
 
Hanilein
Newbies
*
Offline


Posts: 6
Location: New Zealand
Joined: Nov 26th, 2014
Re: How to use Assembler together with C++ / Linker problem
Reply #7 - Nov 27th, 2014 at 10:02pm
Print Post  
Hi Tim,

by packing together and stripping some unneeded code for the zip you've been asking for I meanwhile found out that it has to do with the presence/absence of the assembler source codes in the project directory. As soon as the source files are in the project directory the error appears(!). That happens, if you add the files in the library folder "Serial595" to the project to be able to modify them. Either Atmel Studio or Visual Micro copies these source codes in the project folder.
I played around with various constellations and that's what I learned until now:
  • Assembler source codes must live in a subfolder of .\Sketchbook\libraries, in my case \Serial595, which is the name of the library. 
  • This library must be added to the project using the menu path Project - Add/Import Sketch Library - User.
  • The assembler file extension is .S. The function definition in the assembler file has to be global, for the function void foobar(void) it is:   
         .global foobar
         foobar:

    A header file declaring the function(s) with the extension .h is included in the sketch file. The declaration for the function is:
         extern "C" {void foobar(void);}
  • Do not add these files to the project in Atmel Studio, they are copied in the sketch folder and producing the error undefined reference to `foobar'!
  • To edit the assembler source, just open the files in the library subfolder.
  • The Arduino IDE does not show that error if the source files are in the sketch directory as well as in the library directory. However, it simply ignores the files in the sketch directory (which is very bad).
That works somehow at the moment for me, but:
  • The error message undefined reference is misleading. That looks like a linker error. A message like 'There is a source I cannot deal with' or something like that would be better.
  • I'd really like to have my assembler sources somewhere in the solution explorer accessible, they are part of the project.
  • A working and seamless integration of assembler libraries would be another advantage in comparison to the Arduino IDE.
The email with the files is on it's way.
Thank you very much for your help and time.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12186
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How to use Assembler together with C++ / Linker problem
Reply #8 - Nov 28th, 2014 at 8:49pm
Print Post  
Hi,

Thanks for the update. Some extra info that might help

To include an arduino library in a sketch the header files of the library must be #include "header.h" in the main sketch code. This is what the Visual Micro "project>add/import sketch library does"

A library must be included in the main sketch if it is used in any cpp files of the sketch.

.............

It was good that you report this. Although assembler was being correctly compiled with Visual Micro and Arduino 1.0.x it failed with Arduino 1.5.x. That is fixed for the next release but does not affect you.

I wasn't aware that the Arduino build process does not support assembler in the sketch code. I am not sure if that is intentional or not so will investigate what should or should not happen to sketch source codes.

thanks again


  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint