Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
Support requests without the output above may be impossible to answer, so please help us to help you
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Page Index Toggle Pages: 1
Send Topic Print
Problems with c++/h files (Read 13993 times)
Barak Biber
Newbies
*
Offline



Posts: 3
Problems with c++/h files
Mar 3rd, 2013 at 11:10am
 
To make my code cleaner I tried to separate the code to different files, but I encountered a problem.

I got a file Defines.h
[code]//////////////////////// Global variables ////////////////////////////////
unsigned int g_currentMillis = 0;

int g_stuckCount = 0;

ACTION g_currentACTION;


//////////////////////// Global classes //////////////////////////////////

// The ping uses the trigger pin to send the pulse and the echo pin to read
//PING(triggerPin, echoPin)
PING leftPing(4, 5);
PING rightPing(2, 3);

//Engine(rightEnginePin, leftEnginePin, rightEnginePinReverse, leftEnginePinReverse, speedRes)
Engine myEngines(10 ,6 ,11, 9, 20);[/code]

I declare in it my globals(among other things) but for some reasons it keeps saying for each global [quote]Functions.cpp.o : :C:\Users\DaAn\AppData\Local\VMicro\Arduino\Builds\ArduinoCreature\uno/Functions
.cpp:9: multiple definition of `g_stuckCount'
ArduinoCreature.cpp.o : :(.bss.g_stuckCount+0x0): first defined here'[/quote]
Obviously the header is surrounded with a #ifdef header guard but still the error.

I do include it twice, once in my .ino file and once in Functions.h file in my project, but even when I include it only in the header (which is included in the .ino file) it displays the problem.
It's also included in the .vsarduino.h file made by the visual micro plugin.

Thanks for any help :)
Back to top
« Last Edit: Mar 3rd, 2013 at 11:11am by Barak Biber »  
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: Problems with c++/h files
Reply #1 - Mar 3rd, 2013 at 11:55am
 
Hello,

The vsarduino.h is not included in compile so it will not be the problem. File names that start with "." are not included in Arduino compile so this is an Arduino rule that is safe for us to work with.

So the problem will be with your code structure.

Check that you do not have a backup of the .h file in the sketch folder. The compile ignores the vs project and uses the Arduino rules, which means that every code file in the folder will be compiled.

You can see this an Arduino code problem because you should see the same error if you attempt to compile with the Arduino.exe. This means you can get help on arduino.cc/forum.

Thanks
Back to top
 
WWW  
IP Logged
 
Barak Biber
Newbies
*
Offline



Posts: 3
Re: Problems with c++/h files
Reply #2 - Mar 3rd, 2013 at 12:00pm
 
Okay thanks I'll ask on the arduino forum (and the files are not a library they are project specific they exist only within the sketch folder)
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: Problems with c++/h files
Reply #3 - Mar 3rd, 2013 at 12:04pm
 
It's good they only exist in the sketch folder but make sure you do not have any copies (backups) also in the sketch folder.
Back to top
« Last Edit: Mar 3rd, 2013 at 12:05pm by Visual Micro »  
WWW  
IP Logged
 
Barak Biber
Newbies
*
Offline



Posts: 3
Re: Problems with c++/h files
Reply #4 - Mar 3rd, 2013 at 12:33pm
 
Thanks I made sure of it. Smiley
Eventually I just solved it using a "Defines" class with static variables.
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: Problems with c++/h files
Reply #5 - Mar 3rd, 2013 at 1:35pm
 
Great. Thanks for the update
Back to top
 
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print