Error 2

For some reason I am getting an error and I have no idea what the problem is
This is what it shows in output:

[info]: Saving Project …

[info]: Project saved!

windows build for platform vexv5

“CXX src/main.cpp”

“CXX src/robot-config.cpp”

“LINK build/demo-2019-11-14T17-48-38.elf”

build/src/robot-config.o:(.bss.Controller1+0x0): multiple definition of `Controller1’

build/src/main.o:(.bss.Controller1+0x0): first defined here

build/src/robot-config.o:(.bss.LeftMotor+0x0): multiple definition of `LeftMotor’

build/src/main.o:(.bss.LeftMotor+0x0): first defined here

build/src/robot-config.o:(.bss.RightMotor+0x0): multiple definition of `RightMotor’

build/src/main.o:(.bss.RightMotor+0x0): first defined here

build/src/robot-config.o:(.bss.axMotor+0x0): multiple definition of `axMotor’

build/src/main.o:(.bss.axMotor+0x0): first defined here

build/src/robot-config.o:(.bss.bxMotor+0x0): multiple definition of `bxMotor’

build/src/main.o:(.bss.bxMotor+0x0): first defined here

build/src/robot-config.o:(.bss.cxMotor+0x0): multiple definition of `cxMotor’

build/src/main.o:(.bss.cxMotor+0x0): first defined here

build/src/robot-config.o:(.bss.dxMotor+0x0): multiple definition of `dxMotor’

build/src/main.o:(.bss.dxMotor+0x0): first defined here

build/src/robot-config.o:(.bss.oxMotor+0x0): multiple definition of `oxMotor’

build/src/main.o:(.bss.oxMotor+0x0): first defined here

build/src/robot-config.o:(.bss.xxMotor+0x0): multiple definition of `xxMotor’

build/src/main.o:(.bss.xxMotor+0x0): first defined here

make: *** [vex/mkrules.mk:18: build/demo-2019-11-14T17-48-38.elf] Error 1

[error]: make process closed with exit code : 2

@Gobble. Can you post your code, that will really help.

#include "robot-config.cpp"
int main()
{   
while(true)
{
        LeftMotor.spin (fwd, (Controller1.Axis3.value() + Controller1.Axis4.value())/2, ::pct);
        RightMotor.spin (fwd, (Controller1.Axis3.value() - Controller1.Axis4.value())/2, ::pct);
        oxMotor.spin (fwd, (Controller1.Axis1.value()), ::pct);

   while(Controller1.ButtonUp.pressing())
        {
        axMotor.spin (reverse,50,::rpm);  
        bxMotor.spin (reverse,50,::rpm);  
        LeftMotor.spin (fwd, (Controller1.Axis3.value() + Controller1.Axis4.value())/2, ::pct);
        RightMotor.spin (fwd, (Controller1.Axis3.value() - Controller1.Axis4.value())/2, ::pct);
        oxMotor.spin (fwd, (Controller1.Axis1.value()), ::pct);
        }
   while(Controller1.ButtonDown.pressing())
        {
        axMotor.spin (fwd,50,::rpm);
        bxMotor.spin (fwd,50,::rpm);  
        LeftMotor.spin (fwd, (Controller1.Axis3.value() + Controller1.Axis4.value())/2, ::pct);
        RightMotor.spin (fwd, (Controller1.Axis3.value() - Controller1.Axis4.value())/2, ::pct);
        oxMotor.spin (fwd, (Controller1.Axis1.value()), ::pct);
        }
        bxMotor.stop();
        axMotor.stop();
   while(Controller1.ButtonX.pressing())
        {
        cxMotor.spin (fwd,1000,::rpm);
        dxMotor.spin (fwd,1000,::rpm);
        LeftMotor.spin (fwd, (Controller1.Axis3.value() + Controller1.Axis4.value())/2, ::pct);
        RightMotor.spin (fwd, (Controller1.Axis3.value() - Controller1.Axis4.value())/2, ::pct);
        oxMotor.spin (fwd, (Controller1.Axis1.value()), ::pct);
        }
   while(Controller1.ButtonY.pressing())
        {  
        cxMotor.spin (reverse,1000,::rpm);
        dxMotor.spin (reverse,1000,::rpm);  
        LeftMotor.spin (fwd, (Controller1.Axis3.value() + Controller1.Axis4.value())/2, ::pct);
        RightMotor.spin (fwd, (Controller1.Axis3.value() - Controller1.Axis4.value())/2, ::pct);
        oxMotor.spin (fwd, (Controller1.Axis1.value()), ::pct);
        }
        cxMotor.stop();
        dxMotor.stop();
   while(Controller1.ButtonLeft.pressing())
        {
        xxMotor.spin (fwd,60,::rpm);
        LeftMotor.spin (fwd, (Controller1.Axis3.value() + Controller1.Axis4.value())/2, ::pct);
        RightMotor.spin (fwd, (Controller1.Axis3.value() - Controller1.Axis4.value())/2, ::pct);
        oxMotor.spin (fwd, (Controller1.Axis1.value()), ::pct);
        }
        xxMotor.stop();
   while(Controller1.ButtonRight.pressing())
        {
        xxMotor.spin (reverse,60,::rpm);
        LeftMotor.spin (fwd, (Controller1.Axis3.value() + Controller1.Axis4.value())/2, ::pct);
        RightMotor.spin (fwd, (Controller1.Axis3.value() - Controller1.Axis4.value())/2, ::pct);
        oxMotor.spin (fwd, (Controller1.Axis1.value()), ::pct);          
       }
   
        xxMotor.stop();
   while(Controller1.ButtonY.pressing())
        {  
        cxMotor.spin (reverse,30,::rpm);
        dxMotor.spin (reverse,30,::rpm);  
        LeftMotor.spin (fwd, (Controller1.Axis3.value() + Controller1.Axis4.value())/2, ::pct);
        RightMotor.spin (fwd, (Controller1.Axis3.value() - Controller1.Axis4.value())/2, ::pct);
        oxMotor.spin (fwd, (Controller1.Axis1.value()), ::pct);      
        }
        cxMotor.stop();
        dxMotor.stop();
    while(Controller1.ButtonL1.pressing())
        {
        cxMotor.spin (reverse,30,::rpm);
        dxMotor.spin (reverse,30,::rpm);
        LeftMotor.spin (fwd, (Controller1.Axis3.value() + Controller1.Axis4.value())/2, ::pct);
        RightMotor.spin (fwd, (Controller1.Axis3.value() - Controller1.Axis4.value())/2, ::pct);
        oxMotor.spin (fwd, (Controller1.Axis1.value()), ::pct);
         }
     while(Controller1.ButtonL2.pressing())
        {
        cxMotor.spin (fwd,30,::rpm);
        dxMotor.spin (fwd,30,::rpm);
        LeftMotor.spin (fwd, (Controller1.Axis3.value() + Controller1.Axis4.value())/2, ::pct);
        RightMotor.spin (fwd, (Controller1.Axis3.value() - Controller1.Axis4.value())/2, ::pct);
        oxMotor.spin (fwd, (Controller1.Axis1.value()), ::pct);
        }
         while(Controller1.ButtonR1.pressing())
         {
        cxMotor.spin (reverse,30,::rpm);  
        dxMotor.spin (reverse,30,::rpm);  
        xxMotor.spin (reverse,60,::rpm);
         }
         while(Controller1.ButtonR2.pressing())
         {
        cxMotor.spin (fwd,30,::rpm);  
        dxMotor.spin (fwd,30,::rpm);  
        xxMotor.spin (fwd,60,::rpm);  
         }
 
}    
}

why are you useing whiles when you could be useing ifs ifelses and elses?

I am pretty in in programming and I learned while first and I am used to using it, and I thought if only works once while “while” works as long as you hold the button

o ok so I beleave what is happening is that many while loops inside the other while loop can not be read properly and that is why it is giving you that error.

I don’t know if code that well. Can you show me how should it look?

Your errors indicate you are defining your objects multiple times. When you include vex.h you are also including robot-config.cpp. You don’t need that #include ‘robot-config.cpp’ In main.cpp.


This is not related to why your code will not build:

Your while loops are another thing. When holding a button the rest of your code isn’t executing. Since it’s all in a while loop already you can replace that with if statements as it’ll check if you are holding the button or not continually anyway.

1 Like

I agree with you @JamesChase since it can cause the robot to read everything at the same time, causing the robot to overload making the error that you see before you. The best solution for this is to convert that program to if, else if, and else functions. It also makes it easier for you to program your robot since it allows you to hook up multiple lines of code to the different buttons using less complexity.

How does a while loop logic error result in the computer (not brain) thinking things were defined twice?

While(true){
    If(buttonpressed){
        Spin
    }
    Else If(otherbuttonpressed){
        Spinbackwards
    }
    Else{
        Stopspinning
    }
}

What this does is that it continually checks if the buttons are being pressed (since it’s all in a while loop) and if it isn’t being pressed it’ll stop the motor.

1 Like

Yeah, @Deicer is right here, using while loops to check for button presses like that is not ideal, and doesn’t do what you probably want it to do, but will not stop your code from compiling. It’s important to distinguish between compiler errors and runtime errors.

You should never need to #include a .cpp file, the compiler takes care of that sort of thing for you. Only #include .h files.

1 Like

If you are learning Vex programming, I would suggest starting with a competition template. If using v5 text, you can load a template by clicking the file button in top right, then clicking open example, and then choosing the competition template. This will give you all the necessary code for a competition program. As for your include statements, you need a #include “vex.h” along with any other include statement for the libraries you are using. I doubt you are using any other libraries, so including the vex header file should be all you need. As for you compiler error, this is from instantiating multiple objects with the same name. This is probably resulting from including the robot config file in your program. Since the compiler already includes this file, you are essentially loading it again, causing it to instantiate 2 copies of all your objects.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.