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) VS2017/VM linker still fails, compiles fine in Arduino IDE (Read 3877 times)
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
VS2017/VM linker still fails, compiles fine in Arduino IDE
Feb 1st, 2019 at 2:02am
Print Post  
I'm still trying to figure out why the link step fails with VS2017CE/VM, but works fine in the Arduino IDE.

I have a very simple Example program for the MPU6050.  The library files are all in the sketchbook folder.  

The example compiles without errors or drama in the Arduino IDE  V1.8.7, but in VS2017/VM it blows a whole bunch of errors in the form of 

ccC9SzMc.ltrans0.ltrans.o*: In function main
   (.text.startup+0x1e4): undefined reference to MPU6050::initialize()

for every call to a MPU6050 class function.

I have attached a zip file containing the .INO file, all the required library files and the verbose compiler outputs from both the VS2017/VM setup and the Arduino configuration.   This should compile cleanly on any Windows PC, at least in the Arduino IDE.

The frustrating thing is, this USED to work fine in VS2017/VM and now I have descended into some kind of header file hell; I must have done something really bad in a previous lifetime Sad.

I know Tim and others here have been very patient as I have tried to work through all this, but I'm pretty much at wit's end here.

I'm beginning to believe the VS2017/VM configuration is corrupted in some way, and I'm wondering it  might be useful to try to uninstall the entire VS2017/VM environment and build it back up again.  I'm perfectly willing to do that (after all, it can't be any worse than what I have now!), but I'm not quite sure what the best way to do that would be.  How would you recommend I go about removing all traces of VM from VS2017, removing all traces of VS2017 from my PC, and then putting it all back together again?

TIA,

Frank
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: VS2017/VM linker still fails, compiles fine in Arduino IDE
Reply #1 - Feb 1st, 2019 at 2:34am
Print Post  
Tim,

Saw in another post your advice about renaming the 'arduino15' folder and restarting VM. I did this and confirmed that the folder was recreated when VS/VM started.  However, it did not change the result - the example file I used still fails with the same errors.

Frank
  
Back to top
 
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: VS2017/VM linker still fails, compiles fine in Arduino IDE
Reply #2 - Feb 1st, 2019 at 3:14am
Print Post  
Also, just discovered I didn't have compiler warnings turned on in the Arduino IDE.  When I re-ran the compile with 'Default' warning level, I got the same warnings (but not the same linker errors) as I did in the VS2017/VM setup, namely:

Code
Select All
Linking everything together...
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-gcc" -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections,--relax -mmcu=atmega2560 -o le.ino.elf" p.o" pp.o" MP6_Example.ino.cpp.o" Wire.cpp.o" utility\\twi.c.o" 54c.a" "-LC:\\Users\\Frank\\AppData\\Local\\Temp\\arduino_build_582967" -lm
C:\Users\Frank\AppData\Local\Temp\arduino_build_582967\sketch\MPU6050.h:436:7: warning: type 'struct MPU6050' violates one definition rule [-Wodr]

 class MPU6050 {

       ^

C:\Users\Frank\AppData\Local\Temp\arduino_build_582967\sketch\MPU6050.h:436:7: note: a different type is defined in another translation unit

 class MPU6050 {

       ^

 note: the first difference of corresponding definitions is field 'dmpPacketBuffer'

         uint8_t *dmpPacketBuffer;

                  ^

C:\Users\Frank\AppData\Local\Temp\arduino_build_582967\sketch\MPU6050.h:436:7: note: a type with different number of fields is defined in another translation unit

 class MPU6050 {

       ^

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 le.ino.elf" le.ino.eep"
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -R .eeprom le.ino.elf" le.ino.hex"
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-size" -A le.ino.elf"
Sketch uses 15550 bytes (6%) of program storage space. Maximum is 253952 bytes.
 

  
Back to top
 
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: VS2017/VM linker still fails, compiles fine in Arduino IDE
Reply #3 - Feb 1st, 2019 at 3:17am
Print Post  
Also, the example program as compiled in the Arduino IDE does successfully run a DFRobots MPU6050 module, as expected when uploaded to an Arduino Mega 2560 connected to the  MPU6050 module

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


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: VS2017/VM linker still fails, compiles fine in Arduino IDE
Reply #4 - Feb 1st, 2019 at 2:16pm
Print Post  
If you use the verbose option in the arduino ide you will see which libraries and being used and from what location.

If you do same in visual micro then you will see same and maybe then see a difference.

If you can't see a difference then create a very basic project that simply includes the libraries you are working with along with the basic example for the mpu6050 sensor. If that fails you can zip and email the project along with a note of which libs you have installed and from where to info@visualmicro.com

  
Back to top
WWW  
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: VS2017/VM linker still fails, compiles fine in Arduino IDE
Reply #5 - Feb 1st, 2019 at 3:27pm
Print Post  
Tim,

I think that is what I did.  In my first post above I provided a ZIP file containing the verbose outputs from both the VS/VM configuration and the Arduino IDE configuration, along with all the files required to build the project.

Here it is again.

Frank
  

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


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: VS2017/VM linker still fails, compiles fine in Arduino IDE
Reply #6 - Feb 1st, 2019 at 4:36pm
Print Post  
Questions

1) Why have you copied library sources into your project code folder?

2) Why have you switched off "vMicro>Compiler>Deep search for libraries"?

Thanks
  
Back to top
WWW  
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: VS2017/VM linker still fails, compiles fine in Arduino IDE
Reply #7 - Feb 2nd, 2019 at 12:21am
Print Post  
Tim,

The answers to 1) and 2) are both the same.  One of the many problems I was having in attempting to narrow down the cause of the 'one definition rule' warning is that the compiler/linker was pulling in what appeared to be extraneous i2cdev-related libraries, in particular some RTIMULib files.  I wanted to prevent this from happening to see if that was the cause of the problem (it wasn't).

In reading the documentation associated with Jeff Rowberg's i2cdev library, I saw that it recommended placing the appropriate library files either in the Arduino Libraries folder or directly into the sketch folder, so I elected the latter approach.

The reason I disabled the 'Deep Search' option was to simplify the problem.  With it disabled I was reasonably sure the compiler won't try and pull in extraneous files.  For the same reason, I moved all the i2cdev library files to a completely different non-Arduino folder on my PC, so even if the compiler searched the Arduino/Libraries folder, it wouldn't be able to find any other i2cdev library files.

Another reason for this setup is I can, if necessary, modify the local i2cdev files with no fear that my modifications will result in corrupted/unusable 'regular' library files - I can always delete my screwed up local version and start over again with 'pristine' copies from my hidden i2cdev folder.

The bottom line on all of this is I am trying to achieve a stable, constrained-scope configuration to figure out what causes compiling in the VS/VM environment to fail to link, while the same source code assembly (.INO and .CPP/.H files) compiles and links properly, and try and pinpoint the cause of the 'one definition rule' warning.

As it stands now, both compile setups issue the same two warnings.  One (the overflow warning) is understandable and easily fixed, but the other one (the 'one definition rule' warning) is still a mystery.  However, this mystery (which is where I started this odyssey) is clearly a minor problem compared to not being able to compile at all in the VS/VM environment.

I hope this answers your questions.  I've done a lot of troubleshooting in my 50+ year engineering career, and I'm doing my very best to approach this problem in a methodical fashion.  If you think I'm screwing up and should be doing something different, please let me know and I'll be happy to change.  Wink.

TIA,

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


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: VS2017/VM linker still fails, compiles fine in Arduino IDE
Reply #8 - Feb 3rd, 2019 at 1:05pm
Print Post  
If you are not using the libraries in documents\libraries then delete them or just use them as normal without copying local

  
Back to top
WWW  
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: VS2017/VM linker still fails, compiles fine in Arduino IDE
Reply #9 - Feb 3rd, 2019 at 2:01pm
Print Post  
Tim,

I use libraries in the expected way for almost all my projects (some 60+ projects at the moment, and counting...).  However, for troubleshooting this issue I was trying to eliminate the possibility that the compiler was somehow processing extraneous header files from  the same i2cDev library folder, thereby causing the 'one definition rule' violation that started this whole journey.  This may have been a fool's errand, but that was the reason I did it Wink.

Frank
  
Back to top
 
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: VS2017/VM linker still fails, compiles fine in Arduino IDE
Reply #10 - Feb 4th, 2019 at 4:13am
Print Post  
Tim,

OK, I think I've finally nailed the entire thing down (sort of)

So, the original problem (back when I was still trying to drain the swamp) was two linker warnings - one about integer overflow in a calculation, and the other was the dreaded "One Definition Rule" (ODR) warning, which I had never  heard about until now - go figure.

Then, in the process of trying to fix the above problems, things started to blow up on me, resulting in multiple link errors on code that used to compile/link fine - yikes!

Long story short, most of my problems were self-inflicted (you knew that already, I'll bet).  One of the things I did to try and simplify the problem was to remove the i2cDev-related library files from Arduino\Libraries to prevent the compiler/linker from linking in extraneous header files (At the time I thought this might be the cause of the ODR violation).  What actually happened is now Visual Micro couldn't find these files AT ALL, even though they were all in the local project folder and I had 'local files override library files' checked.  

After tearing most of my remaining hair out (and bugging you unmercifully) I created two identical projects, one of which compiled/linked fine (with the ODR warning still) and one of which wouldn't link at all in VS/VM.  However, BOTH projects compiled/linked fine in the Arduino IDE, so now I knew it had to be something in the VS/VM project/solution configuration that was causing the problem.  Eventually I stumbled on the 'solution' in the project that worked, I had earlier added the relevant library .H/.CPP files to the 'working' project using Solution Explorer so they showed up under the 'Header Files' and 'Source Files' folders.  After adding the library files to the non-working project, it started compiling/linking successfully as well.

IMHO, this is a bug in Visual Micro.  If the 'local files override library files' option is enabled, whether or not the files are added to the project in Solution Explorer shouldn't matter.  If files MUST be added to the project via Solution Explorer to be 'seen', then why have the 'local files override...' option at all?  Shouldn't the compiler always process files that are added to projects via the Solution Explorer?

So, now I was back to square 1, with projects that compiled/linked, but still with ODR warnings.  After LOTS of web research, I finally figured it out - the original author of the MPU6050 class had placed an #ifdef/#endif statement in the class definition in a way that (from the compiler's point of view) could result in two different definitions of the same class.  Temporarily commenting out the #ifdef/#endif in the class definition suppressed the ODR warning - SUCCESS!!!


Regards,

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


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: VS2017/VM linker still fails, compiles fine in Arduino IDE
Reply #11 - Feb 5th, 2019 at 5:42pm
Print Post  
So why were you not seeing the warnings in the arduino ide?
  
Back to top
WWW  
IP Logged
 
FrankP
Full Member
***
Offline


Posts: 240
Joined: Oct 19th, 2011
Re: VS2017/VM linker still fails, compiles fine in Arduino IDE
Reply #12 - Feb 6th, 2019 at 4:35am
Print Post  
Tim@Visual Micro wrote on Feb 5th, 2019 at 5:42pm:
So why were you not seeing the warnings in the arduino ide?



Tim,

As I mentioned 3 days ago in this thread, I didn't notice initially that warnings were turned off in the Arduino IDE:

Reply #2 - Feb 1st, 2019 at 3:14am:  Also, just discovered I didn't have compiler warnings turned on in the Arduino IDE.  When I re-ran the compile with 'Default' warning level, I got the same warnings (but not the same linker errors) as I did in the VS2017/VM setup, namely: ....

Frank

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