VS Arduino
Visual Micro >> Usb/Serial/WiFi Debugging >> Problems compiling custom library in debug mode
https://www.visualmicro.com/forums/YaBB.pl?num=1359648545

Message started by Woodcam on Jan 31st, 2013 at 4:09pm

Title: Problems compiling custom library in debug mode
Post by Woodcam on Jan 31st, 2013 at 4:09pm
Added <file>.cpp and <file>.h to project to implement MVC architecture which in turn uses the RTClib and Wire libraries. The problem is that the Arduino library references do not resove correctly when compiling with the debug option. The same problem occurs when the files are either in the immediate local directory with the controller *.ino file or when they are moved to their own respective library location in the Arduino library hierarchy.  :'(

The error:

Compiling debug version of 'TimeTest2' for 'Arduino Uno'
ChickCoopCtl.cpp.o : : In function `ChickCoopCtl::getTime(char*, char*)':
ChickCoopCtl.cpp : now()'
ChickCoopCtl.cpp : now()'
ChickCoopCtl.cpp.o : : In function `ChickCoopCtl':
ChickCoopCtl.cpp : undefined reference to `Wire'
ChickCoopCtl.cpp : undefined reference to `Wire'
ChickCoopCtl.cpp : begin()'
ChickCoopCtl.cpp : begin()'
avr-objcopy* : : 'C:\Users\Owner\AppData\Local\VMicro\Arduino\Builds\TimeTest2\uno\TimeTest2.elf': No such file
avr-objcopy* : : 'C:\Users\Owner\AppData\Local\VMicro\Arduino\Builds\TimeTest2\uno\TimeTest2.elf': No such file

The first compiler pass succeeds but the link level fails. This same code compiles and loads successfully if the debug option is set to release. I have changed the references to wire to the underlying TwoWire class and instansiated RTC_DS1307 rather than use the static class reference to no avail - both versions work in release but above errors in debug. :'(

Title: Re: Problems compiling custom library in debug mode
Post by Visual Micro on Jan 31st, 2013 at 6:04pm
Hi,

I have split this out to a new thread because it would be unfair for other people who have switch on email notifications to receive emails about your issue (which is also different to the original thread).

It is much better to make new threads with your own specific problems. It makes it easier to discuss the issue without having to read other unrelated posts and allows you to specify a more accurate title for the post.

Because this post only applies to debug compile I have also moved this thread from "Project Guidance" to the debugger beta section.

Please zip and email your sketch folder and the library so that I can try it. Also let me know (overview) of what breakpoints you have set in which source files.

Thanks


Title: Re: Problems compiling custom library in debug mode
Post by Woodcam on Feb 1st, 2013 at 4:12pm
Problem solved :)

The linker looks at the base Arduino <target>.ino file to resolve core library links. All user library code includes that reference core libraries must also be added to the base <target>.ino file.

In addition, in the <target>.ino file, the <stdint.h> library must be included before the Wire and RTClib includes in order to resolve the unint<width>_t type references.


Title: Re: Problems compiling custom library in debug mode
Post by Visual Micro on Feb 1st, 2013 at 5:36pm
Thanks for the update.

So am I right in saying that in your .ino program source you are including elements of the arduino core manually?

Title: Re: Problems compiling custom library in debug mode
Post by Woodcam on Feb 1st, 2013 at 6:40pm
The core libraries are added by using the VS Add Arduino Library menu dropdown, the stdint.h reference must be added manually.

Title: Re: Problems compiling custom library in debug mode
Post by Visual Micro on Feb 1st, 2013 at 9:28pm
Do you think the debugger should include these files automatically, I'm not sure if that would be possible because it might break the flexibility of allowing people to override the types??

Maybe it could do something automatically and provide a config setting to disable the feature.

I'm not sure how to proceed with this one but it's good you found the solution and great that you published it.

Title: Re: Problems compiling custom library in debug mode
Post by Woodcam on Feb 1st, 2013 at 10:40pm
I am not an Arduino expert 8-), I found this solution from another post on the web, although my initial suspicion that it was a linker problem proved correct. The Arduino linker uses the library includes in the <target>.ino to resolve link references and does not check user library files for cross references to other or core libraries.

Any changes would have to be made cognizant of the Arduino environment.

Title: Re: Problems compiling custom library in debug mode
Post by Visual Micro on Feb 2nd, 2013 at 3:07am
You probably know more about it than me. The debugger is simple and just includes the arduino.h which I would have expected to provide coverage for the entire arduino core.

I'm having a problem understanding why this failed with the debugger enabled. Do you have tracepoints in cpp files or are you just using .ino files.

The debugger isn't supposed to be doing anything with libraries at the moment so should be unaffected by any libs.

To test the debug compile problem, can I simply include the libraries you mention in n empty arduino sketch and try to debug? Will I hit the problem you hit?

Title: Re: Problems compiling custom library in debug mode
Post by Woodcam on Feb 3rd, 2013 at 3:55pm
There is a wiki site on Google that documents Arduino and the compile link process - http://code.google.com/p/arduino/.

There is a compilation section which also points out that references to library files not referenced in the main <target>.ino file must be included in the <target>.ino. Once this accepted and proscribed procedure is followed there is no error between the release and debug compilations. In other words this procedure must be followed to adhere to the Arduino environment.

Title: Re: Problems compiling custom library in debug mode
Post by Visual Micro on Feb 3rd, 2013 at 5:27pm
Hi,

Yes I know the compile process well however I am obviously not being clear with my question.

You say the the project compiled fine in release mode but not in debug mode?

Sorry I don't understand the difference?

The debugger doesn't reference any libraries.

What am I missing? Sorry to be a pain.

Title: Re: Problems compiling custom library in debug mode
Post by Woodcam on Feb 3rd, 2013 at 7:33pm
The original post refers to the fact that the linker failed because I did not include the referenced libraries in the <target>.ino file. The subsequent posts detail the solution, referenced libraries must be included in the <target>.ino file even when not referenced directly in the <target>.ino file. Once the solution procedures are followed there are no errors either in release or debug compilations. :)

Title: Re: Problems compiling custom library in debug mode
Post by Visual Micro on Feb 3rd, 2013 at 8:04pm
Hi,

Yes I understand that but your original post said that it linked fine in "Release" mode but not in "Debug".

I also understand that with some arduino libs you need to add in certain parts of the arduino core to the sketch manually.

So adding <stdint.h> early in the sketch code solves the issue but from my perspective a debug compile should work the same as a release compile.

From what you say, am I correct in thinking that the unint<width>_t reference in the vm debugger code would have caused the difference between the two compilations?

If so, then I am wondering if vm should automatically force <stdint.h> into the debug compile.

Thanks

Title: Re: Problems compiling custom library in debug mode
Post by Woodcam on Feb 3rd, 2013 at 9:20pm
The  the unint<width>_t reference is a compile error, not a linker error. The Arduino compiler does not load stdint.h automatically while VS does.

Referencing stdint.h automatically pre-compile probably will not be affect other compile outcomes.

Title: Re: Problems compiling custom library in debug mode
Post by Visual Micro on Feb 3rd, 2013 at 11:34pm
Hi, Yes I forgot to say that I can add it to the main .ino during debug compile, vm already adds other stuff when required. Then it will be picked up in the same way as if the user had added it to the sketch.

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