VS Arduino
Visual Micro >> Project Guidance >> Problems with c++/h files
https://www.visualmicro.com/forums/YaBB.pl?num=1362309028

Message started by Barak Biber on Mar 3rd, 2013 at 11:10am

Title: Problems with c++/h files
Post by Barak Biber on 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'

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 :)

Title: Re: Problems with c++/h files
Post by Visual Micro on 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

Title: Re: Problems with c++/h files
Post by Barak Biber on 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)

Title: Re: Problems with c++/h files
Post by Visual Micro on 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.

Title: Re: Problems with c++/h files
Post by Barak Biber on Mar 3rd, 2013 at 12:33pm
Thanks I made sure of it. :)
Eventually I just solved it using a "Defines" class with static variables.

Title: Re: Problems with c++/h files
Post by Visual Micro on Mar 3rd, 2013 at 1:35pm
Great. Thanks for the update

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