Pros cortex help, multiple definitions even though there isnt

Having errors compiling my code using PROS cortex. It’s been a while since I used c so it may be that.
These are some of the errors I have been receiving:
image

I checked opcontrol.c, drive.c, and init.c and saw no problems. It may be a problem with main.h

Here is the github link to my code:

Thanks!

Ok, the problem you’re running into is that you’re setting the values of those variables in drive.h, so by including that file both in drive.c and in main.h (which is subsequently included in init.c) you now have multiple definitions of the variables. Consider setting the values for the variables in drive.c

Also, instead of using variables for these values

float EncToInches = (4.1 * 3.1415926535) / 900.0;
float QEncToInches = (4.1 * 3.1415926535) / 360.0;

Use define statements, like so

#define EncToInches (4.1 * 3.1415926535) / 900.0;
#define QEncToInches = (4.1 * 3.1415926535) / 360.0;

This makes EncToInches and QEncToInches into macros, so at compile time, they are replaced with the values they represent.

(I haven’t done any coding in a while, so I might have messed up, but this seems right)

4 Likes

To build on @thermonuke ‘s point, you can also move the definition into the source and only declare it in the header file

//in myFile.hpp
extern int x; // declaration

//in myFile.cpp
int x = 5; // definition and re-declaration

Also another thing I want to say is that, nice code base! Frankly it is better than most codes I see on this forum.

4 Likes