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 Simple example of not finding header (Read 3363 times)
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Simple example of not finding header
Dec 26th, 2015 at 12:05am
Print Post  
I created a simple example of a project that includes two libraries (ClassA and ClassB). All the code is in the Zip file attached. It won't compile, but in VM it doesn't say why. In the Arduino IDE, it says: 

D:\Users\Bob.ObigOne\Documents\Arduino\LibraryTest\LibraryTest.ino:1:20: fatal error: ClassA.h: No such file or directory

#include <ClassA.h>

                    ^

compilation terminated.

exit status 1
Error compiling.

I created all of the code (including the libraries) using VS 2013 ++ Visual Micro. 

So why can't the compiler find the header files?
  

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: Simple example of not finding header
Reply #1 - Dec 26th, 2015 at 12:22am
Print Post  
Hi,

You will see that error in the arduino ide because it doesn't support local libraries. You would need to move/copy them to your documents\arduino\libraries folder for it to see them.

The problem is that you have created the two libraries but they are not included in the project. 

In "show physical files on disk mode" of the solution explorer I would expect you see red exclamation marks next to the .cpp and .h file names

In "show filtered view" I would expect the libraries .cpp and .h files do not appear in the "Header Files" and "Source Files" branches.

Therefore you need to be viewing "show physical files on disk mode" so that you can right click the source codes and select the "Include in project" option. 

You can hold the CTRL key and select multiple cpp/h files then include them all at once if that's easier for you.

  
Back to top
WWW  
IP Logged
 
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Re: Simple example of not finding header
Reply #2 - Dec 26th, 2015 at 5:56am
Print Post  
Thank you, but I am not able to find a "show physical files on disk" option or a "show filtered view". Where do I find them?
  
Back to top
 
IP Logged
 
Bob Jones
Full Member
***
Offline


Posts: 210
Location: Bellingham, WA
Joined: Dec 4th, 2015
Re: Simple example of not finding header
Reply #3 - Dec 26th, 2015 at 6:08am
Print Post  
In the example, LibraryTest.ino explicitly includes ClassA.h, but this #include statement fails (line 1 of Library.ino). 

All of the files were created within VS/VM by using VM->Add Code -> Add new Arduino library. 

The compile fails with "collect2.exe*:error: 1d returned 1 exit status" followed by "Error creating .elf".

Here is a screen shot of my solution explorer:
  

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: Simple example of not finding header
Reply #4 - Dec 26th, 2015 at 1:48pm
Print Post  
Thanks for the info. That looks fine and means the project you sent hadn't yet been saved, I should have mentioned to do that.

So I included your code and tried to compile and could see the following issues in your code. 

Here are a few tips:-

The compiler error that I can see is as follows :-

Code
Select All
ClassA.cpp.o:In function `ClassA::methodA1()
ClassA.cpp:methodB1()
ClassA.cpp.o:In function `ClassA::methodA2()
ClassA.cpp:methodB2()
collect2.exe*:error: ld returned 1 exit status
Error creating .elf
 



The error isn't very helpful so I will look into a better message. In fact if you switch on "Visual Micro>Verbose Messages" you get a better error:-

Code
Select All
ClassA.cpp:6:20: fatal error: ClassB.h: No such file or directory
:#include "ClassB.h"
:compilation terminated
 



The error is because you have included the ClassB library in your ClassA code but not in the master .ino. 

Historically for Arduino if you want to use any libraries in a project you must include them in the master .ino source. 

This area of development is changing at the moment to make it easier for users but this is how it has been for 5+ years

This still applies even if the .ino does not use the "other" library. So I changed your .ino code as follows adding the #include for ClassB:-

Code
Select All
#include <ClassA.h>
#include <ClassB.h>
ClassA classA;
void setup() {
    classA.methodA1();
}

void loop() {
    classA.methodA2();
}

 



After that fix your code will still fail. Again not great error messages although the Visual Studio intellisense will show the error.

The problem is your ClassB header defines a constructor but the classB.cpp doesn't have one. Remove ClassB(); from the ClassB.h

Incorrect
Code
Select All
class ClassB {
public:
    ClassB();
    void methodB1();
    void methodB2();
};
 



Correct
Code
Select All
class ClassB {
public:
    void methodB1();
    void methodB2();
};
 



tip: If you switch on "Visual Micro>Compiler Warnings" you get a good error message for the first issue in your code. It's better than Verbose because there is less 'other stuff' in the output Smiley
« Last Edit: Dec 26th, 2015 at 2:01pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint