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 [2]  Send TopicPrint
Very Hot Topic (More than 25 Replies) Using and debugging my own library (Read 20973 times)
Bas
Junior Member
**
Offline


Posts: 50
Joined: Feb 20th, 2017
Re: Using and debugging my own library
Reply #20 - Feb 22nd, 2017 at 7:54am
Print Post  
Thanks for the elaborate answer.
I still don;t feel very confident about understanding the use of shared libraries, but you have given me some things to look at this evening.

I think it would be very helpfull to add a tutorial to your site (based on the latest available version of VS and the VM exgtension) on how to start a a user-defined library and how to use it in a user project with Visual studio, especially when you don't store everything in the fixed folders or folder structure that Arduino is making you use. 

I've noticed on more than one occasion that Arduino has more than a few quirks if you want to structure your own projects in a different way. Its not very flexible about that Wink
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using and debugging my own library
Reply #21 - Feb 22nd, 2017 at 11:16am
Print Post  
SmileyI will try to explain but your libs can still be in normal Arduino locations in which case the shared project simply provides something that visual studio can use in the solution explorer and to provide intrllisense.


Creating from scratch is simply a matter of using the standard visual studio file,new,project , shared project.


Sounds like the tutorial needs to explain about Arduino too
  
Back to top
WWW  
IP Logged
 
Bas
Junior Member
**
Offline


Posts: 50
Joined: Feb 20th, 2017
Re: Using and debugging my own library
Reply #22 - Feb 22nd, 2017 at 8:12pm
Print Post  
Tim,

I'm still not able to get this thing working ... Sad
As I understand from your answers, the location of the library, sketchbook settings in Arduino or VS should not matter anymore. Is this correct?

On the Blog-page  about Cross-platform library devleopment, you write "Visual Micro also provides a simple way to create a shared project for an existing Arduino library."

How is this done?

Can you please provide me with a sample solution file containing a Arduino project and a shared local Arduino library from which the debugging into the library is working? I'm really missing a step by step instruction on how to create such a thing and get it working
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using and debugging my own library
Reply #23 - Feb 22nd, 2017 at 10:05pm
Print Post  
Sketch book doesn't matter if you have a reference to a shared project.

The link I gave to the shared lib doc shows how to create a project from a lib (see below) 

However as I said, your project worked find for me and I could see the debug commands in the output. So I suggest you switch on the verbose option I mentioned so you can then go have a look at sensor.cpp in the build folder and see if it contains the debug commands where the breakpoint should be. Also to ensure you removed the breakpoint in the .h.

http://www.visualmicro.com/post/2017/01/16/Arduino-Cross-Platform-Library-Develo...




  
Back to top
WWW  
IP Logged
 
Bas
Junior Member
**
Offline


Posts: 50
Joined: Feb 20th, 2017
Re: Using and debugging my own library
Reply #24 - Feb 22nd, 2017 at 11:03pm
Print Post  
What makes user installed libraries appear in the User combobox control, because my framework is not showing there?
Where do they have to reside, and are there any special file requirements?

I tried the other approach to create a shared project mentioned in your blog to use File>New>Project>C++>Misc>Shared Project to create a empty shared project but the option Misc is not available in the new project dialog.

I'm real sorry to bother you with all this .. does not make me feel very competent to be honest  Sad
I really appreciate the effort you take to get me past this initial learning curve ...

Edit:

Ok, I found how to get the library to appear in the combobox:
placed it in a folder named libraries under the sketchfolder settings, and added a library.properties file
Added the library with the Add User lib, and added a reference to it

Now when I build my solution, all functions from the library are defined twice, the linker doesnt like that Sad
Full build log in attachment....
Quote:
DHT11TemperatureSensor.cpp.o (symbol from plugin)*: In function DHT11TemperatureSensor::readRawValue()
(.text+0x0)*: multiple definition of DHT11TemperatureSensor::readRawValue()
DHT11TemperatureSensor.cpp.o (symbol from plugin)*: (.text+0x0): first defined here
ld.exe: Disabling relaxation: it will not work with multiple definitions
 
DHT11TemperatureSensor.cpp.o (symbol from plugin)*: In function DHT11TemperatureSensor::readRawValue()
(.text+0x0)*: multiple definition of DHT11TemperatureSensor:: DHT11TemperatureSensor(unsigned char, int)
DHT11TemperatureSensor.cpp.o (symbol from plugin)*: (.text+0x0): first defined here

(Not a very helpfull error message from VS btw ... would expect at least  enough info to determine the difference between the two DHT11TemperatureSensor.cpp.o files.

Looking at the build folder, I actually do see the DHT11TemperatureSensor.cpp.o file twice with the same timestamp, in the build folder ("..../debug") and in a folder .../debug/SenseFramework. Looks like the file is compiled for the master project once and for the referenced library another time
« Last Edit: Feb 23rd, 2017 at 12:06am by Bas »  

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


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using and debugging my own library
Reply #25 - Feb 23rd, 2017 at 12:27pm
Print Post  
1)

Quote:
Ok, I found how to get the library to appear in the combobox:
placed it in a folder named libraries under the sketchfolder settings, and added a library.properties file
Added the library with the Add User lib, and added a reference to it


This is how both the arduino ide and visual micro works. SketchBook\Libraries is where user libs are installed


2)
File>New>Project>C++>Misc>Shared Project t

Shared projects are a standard part of visual studio and unrelated to visual micro. You can google them if you need help

3)

Why not resend a zip with your solution so I can see what you have done.

4)

Because your project is so big I suggest a new simple test project using a small shared lib such as EEPROM so you can easily see what is happening and how things work.


« Last Edit: Feb 23rd, 2017 at 12:55pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Bas
Junior Member
**
Offline


Posts: 50
Joined: Feb 20th, 2017
Re: Using and debugging my own library
Reply #26 - Feb 24th, 2017 at 8:57pm
Print Post  
Ok, I got a sample project working and my own project almost ..... I think I've got the hang of it now.

What remains is a linking error:
Quote:
Error compiling for board Arduino/Genuino Mega w/ ATmega2560 (Mega 2560)
Debug build failed for project 'CSense'
 
ccmbgiPb.ltrans2.ltrans.o*: In function init
wiring.c:356: undefined reference to setup
wiring.c:356: undefined reference to loop
 
collect2.exe*: error: ld returned 1 exit status


I send you a mail with rar and complete build  log.. would really appreciate if you could take a look at that
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using and debugging my own library
Reply #27 - Feb 24th, 2017 at 8:58pm
Print Post  
Smiley Ignore my email asking for a link

I have seen this if you define and use code from a header without a .cpp. With arduino and gcc only .cpp files are compiled into .o files and then linked. 

If this is the case then you have defined prototypes in your header file(s) so the cpp files are compiled but the linker fails to find the actual code.

......

Unrelated but also important is to use #pragma once at the top of header files of an #if condition.

Code
Select All
#pragma once 



« Last Edit: Feb 24th, 2017 at 9:04pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Bas
Junior Member
**
Offline


Posts: 50
Joined: Feb 20th, 2017
Re: Using and debugging my own library
Reply #28 - Feb 24th, 2017 at 9:08pm
Print Post  
Tim@Visual Micro wrote on Feb 24th, 2017 at 8:58pm:

......

Unrelated but also important is to use #pragma once at the top of header files of an #if condition.

Code
Select All
#pragma once 




What do you mean by "header files of an #if condition" ?"

[Edit]
I added .cpp files for every .h file that didnt have one already, just including the .h file .. but same result. Linker is stil unhappy with something in wiring.c which is part of the Arduino libs

[Edit2]
I've read up on #pragma once .. it should replace the #ifndef guards if I understand correctly
Tried it, but getting loads of :"error: redefinition of ..."  messages
« Last Edit: Feb 24th, 2017 at 9:53pm by Bas »  
Back to top
 
IP Logged
 
Bas
Junior Member
**
Offline


Posts: 50
Joined: Feb 20th, 2017
Re: Using and debugging my own library
Reply #29 - Feb 25th, 2017 at 10:02pm
Print Post  
Ok . I've solved the linker error.

It was caused by the fact that my main .ino file was called CSense.ino and that I used another .cpp/.h combination that was also called CSense.cpp and CSense.h

When I renamed the .cpp and .h the linker error vanished.

I never had this problem when compiling through a batch file which called arduino-builder directly but apparently the Visual Studio / Visual Micro toolchain has some other ideas about this Wink

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


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using and debugging my own library
Reply #30 - Feb 25th, 2017 at 10:22pm
Print Post  
Thanks for the update. 

Yes, it's always been the case for Visual Micro because it was always the case for arduino until quite recently that adding a project_name.cpp to the project would override all .ino files.

I think it needs to become optional by the sounds of it.

It's quite a useful feature, some people like to ditch the .ino system and a project_name.cpp overrides all the .ino code. Not so useful for others Smiley
  
Back to top
WWW  
IP Logged
 
Bas
Junior Member
**
Offline


Posts: 50
Joined: Feb 20th, 2017
Re: Using and debugging my own library
Reply #31 - Feb 25th, 2017 at 10:31pm
Print Post  
Well, I had both Smiley and it worked

But I can understand that it wasnt such a wise descision to use equal names there
I would suggest not allowing it, but then generating an explicit error message... would save a few hours of taking your project apart Smiley
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using and debugging my own library
Reply #32 - Feb 26th, 2017 at 1:16pm
Print Post  
Thanks. Yes it needs some thought. 

A lot of users know it's the way to override all the .ino files and is a useful feature especially in atmel studio with hardware debugging.

In fact if the project is configured for hardware debug there are messages that suggest creating a project_name.cpp containing the .ino code along with link to an example combined .cpp source file. So that's the opposite message to the one that you need.

Some easy things just don't want to be easy Smiley

I think we need a menu item (checkbox switch) that says what it does.


« Last Edit: Feb 26th, 2017 at 1:17pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send TopicPrint