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 Problems with c++/h files (Read 21270 times)
Barak Biber
Newbies
*
Offline


Posts: 3
Joined: Feb 18th, 2013
Problems with c++/h files
Mar 3rd, 2013 at 11:10am
Print Post  
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 : .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 :)
« Last Edit: Mar 3rd, 2013 at 11:11am by Barak Biber »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problems with c++/h files
Reply #1 - Mar 3rd, 2013 at 11:55am
Print Post  
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
Joined: Feb 18th, 2013
Re: Problems with c++/h files
Reply #2 - Mar 3rd, 2013 at 12:00pm
Print Post  
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
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problems with c++/h files
Reply #3 - Mar 3rd, 2013 at 12:04pm
Print Post  
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.
« Last Edit: Mar 3rd, 2013 at 12:05pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Barak Biber
Newbies
*
Offline


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


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problems with c++/h files
Reply #5 - Mar 3rd, 2013 at 1:35pm
Print Post  
Great. Thanks for the update
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint