Exit Code 2 Help

Hi, on my Vex C++ site, we are having trouble compiling the program completely. We keep getting this message in red at the bottom of our code when we compile saying “[error] make process closed with exit code : 2”. We have tried everything to fix it and this is our last resort. Please give us a response soon.

1 Like

Hi @leighar23, welcome to the VEX Forum!

That error message just means “there was an error”. To help you out we’ll need to see:

  1. Your complete program (remember to wrap it in [code] ... [/code] tags for formatting!)
  2. More information about the error you’re getting (copy/paste or screenshot the entire contents of the “output” tab when you try to compile)
6 Likes

“LINK build/VexProject6C.elf”

C:\Program Files (x86)\VEX Robotics\VEXcode Pro V5\sdk/vexv5\libv5rt.a(v5_startup.c.obj): In function `vexMain’:

(.text.vexMain+0xa0): undefined reference to `main’

C:\Program Files (x86)\VEX Robotics\VEXcode Pro V5\sdk/vexv5\libv5rt.a(vex_task.cpp.obj): In function `vex::task::_stopAll()’:

(.text._ZN3vex4task8_stopAllEv+0x34): undefined reference to `main’

C:\Program Files (x86)\VEX Robotics\VEXcode Pro V5\sdk/vexv5\libv5rt.a(vex_competition.cpp.obj): In function `vex::competition::competition()’:

(.text._ZN3vex11competitionC2Ev+0x134): undefined reference to `main’

make: *** [vex/mkrules.mk:18: build/VexProject6C.elf] Error 1

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

1 Like

Excellent – could you also post your complete program?

seems like you either deleted or renamed “main”. Does a new project build ?

2 Likes
/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       C:\Users\dscurry                                          */
/*    Created:      Mon Mar 08 2021                                           */
/*    Description:  V5 project                                                */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller    21           
// Leftmotor            motor         20              
// Rightmotor           motor         19              
// ClawMotor            motor         17              
// ArmMotor             motor         18              
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"
#include <cmath> // std::abs

using namespace vex;

// A global instance of competition
competition Competition;

// define your global instances of motors and other devices here

/*--------------------------------------------------------------------------*/
/*                          Pre-Auonomus Functions                          */
/*                                                                          */
/* You may want to preform some actions before the competition starts.      */
/* Do then in the following function. You must return from this function    */ 
/* or the automus usercontrol tasks will not be started. This               */ 
/* function is only called once after the V5 has been powered on and        */ 
/*  not every time that the robot is disabled.                              */
/*--------------------------------------------------------------------------*/ 

void pre_auton (void) {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // All activites that occur before the competition starts
  // Example: clearing encoders, setting servo positions, 
}

//Settings
double kP = 0.0;
double kI = 0.0;
double kD = 0.0;

//Autonomous Settings
int desiredValue = 200;

int error; //SensorValue - DesireValue : Position
int prevError = 0; //Position 20 milliseconds ago
int derivative;
int totalError;

//Variables modified for use
bool enableDrivePID = true;

int drivePID(){

  while(enableDrivePID){

    //Get the position of both motors
    int leftMotorPosition = Leftmotor.position(degrees);
    int rightMotorPosition = Rightmotor.position(degrees);

    ///////////////////////////////////
    //Lateral Movement PID
    //////////////////////////////////////////////////////
    //Get average of the two motors
    int averagePosition = (leftMotorPosition + rightMotorPosition)/2;

   // potential
    error = averagePosition - desiredValue;

  // derivative
    derivative = error - prevError;


    //code
    prevError = error;
    vex::task::sleep(20);

  }
    return 1; 

}
/*--------------------------------------------------------------------------*/
/*                                                                          */
/*                               Autonomus Task                             */
/*                                                                          */
/* This task is used to control your robot during the autonomus phase of    */
/* a VEX Competition.                                                       */
/*                                                                          */
/* You must modify the code to add your own robot specific commands here.   */
/*--------------------------------------------------------------------------*/

void autonomous(void) {

 vex::task billWiTheScienceFi(drivePID);


/////////////////////////////
//Drivetrain
//Settings
//////////////////////////////////////////////////////////////////////////////

//Driver Control

double turnImportance = 0.5;

while (1) {
/////////////////////////////
//Driver Control
//////////////////////////////////////////////////////////////////////////////

double turnVal = Controller1.Axis1.position(percent);

double forwardVal = Controller1.Axis3.position(percent);

double turnVolts = turnVal * 0.12;
double forwardVolts = forwardVal * 0.12 * (1 - std::abs (turnVolts)/12.0) * turnImportance;

//12 - 12 = 0
//12 + 12= 12 (due to cap)

Leftmotor.spin(forward,  forwardVolts + turnVolts, voltageUnits::volt);
Rightmotor.spin(forward,  forwardVolts - turnVolts, voltageUnits::volt);
////////////////////////////////////////////////////////////////////////////

/////////////////////////////
//Arm Control
////////////////////////////////////////////////////////////////////////////

bool topRightButton = Controller1.ButtonR1.pressing();
bool bottomRightButton = Controller1.ButtonR2.pressing();

if (topRightButton){
  ArmMotor.spin(forward, 12.0, voltageUnits::volt);

}
else if (bottomRightButton){
  ArmMotor.spin(forward, 12.0, voltageUnits::volt);

}
else{
  ArmMotor.spin(forward, 0, voltageUnits::volt);

}
////////////////////////////////////////////////////////////////////////////

//Claw Control
////////////////////////////////////////////////////////////////////////////

bool topLeftButton = Controller1.ButtonL1.pressing();
bool bottomLeftButton = Controller1.ButtonL2.pressing();

if (topLeftButton){
  ClawMotor.spin(forward, 12.0, voltageUnits::volt);

}
else if (bottomLeftButton){
  ClawMotor.spin(forward, 12.0, voltageUnits::volt);

}
else{
  ClawMotor.spin(forward, 0, voltageUnits::volt);

}

// This is the main execution loop for the user control program
// Each time through the loop your program must update motor + servo
// values based on feedback from the joysticks.

//.........................................................................
// Insert user code here. This is where you use the joystick values to
// update your motors, etc.
//.........................................................................

wait(20, msec); // sleep the task for a short amount of time to
                // prevent wasted sources
}
 #include "vex.h"
using namespace vex;


int (main); {
  // Initializing Robot Configuration. DO NOT REMOVE! 
  vexcodeInit();
  Brain.Screen.print("Hello");


}


while (1)
  wait(20,msec);
int num1 =1;
double num2 = 1.2;
char char1 = 'A';
bool bool1 = false;
num1 = (int)num2;
num2 = 3/2.0;   
char1 = 'B';
bool1 = false;
bool1 = true;

/*==
>=
>
<
<=
!-*/

while(1==1){
  // code
  num2 = 2.0;
}

double turnVal = Controller1.Axis1.position(percent);
double forwardVal = Controller1.Axis3.position(percent);
double turnVolts = turnVal *0.12;     
double forwardVolts = forwardVal *0.12; 

//12 - 12 = 0
//12 + 12= 12 (due to cap)

Leftmotor.spin(forward,  forwardVolts - turnVolts, voltageUnits::volt);
Rightmotor.spin(forward,  forwardVolts + turnVolts, voltageUnits::volt);

}

We did delete a “main.” and we don’t know what to put back into the parentases.

I meant to type parentheses

/*----------------------------------------------------------------------------*/
/* <em>/
/</em> Module: main.cpp <em>/
/</em> Author: C:\Users\dscurry <em>/
/</em> Created: Mon Mar 08 2021 <em>/
/</em> Description: V5 project <em>/
/</em> <em>/
/</em>----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Controller1 controller 21
// Leftmotor motor 20
// Rightmotor motor 19
// ClawMotor motor 17
// ArmMotor motor 18
// ---- END VEXCODE CONFIGURED DEVICES ----

#include “vex.h”
#include // std::abs

using namespace vex;

// A global instance of competition
competition Competition;

// define your global instances of motors and other devices here

/*--------------------------------------------------------------------------*/
/* Pre-Auonomus Functions <em>/
/</em> <em>/
/</em> You may want to preform some actions before the competition starts. <em>/
/</em> Do then in the following function. You must return from this function <em>/
/</em> or the automus usercontrol tasks will not be started. This <em>/
/</em> function is only called once after the V5 has been powered on and <em>/
/</em> not every time that the robot is disabled. <em>/
/</em>--------------------------------------------------------------------------*/

void pre_auton (void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();

// All activites that occur before the competition starts
// Example: clearing encoders, setting servo positions,
}

//Settings
double kP = 0.0;
double kI = 0.0;
double kD = 0.0;

//Autonomous Settings
int desiredValue = 200;

int error; //SensorValue - DesireValue : Position
int prevError = 0; //Position 20 milliseconds ago
int derivative;
int totalError;

//Variables modified for use
bool enableDrivePID = true;

int drivePID(){

while(enableDrivePID){

```
//Get the position of both motors
int leftMotorPosition = Leftmotor.position(degrees);
int rightMotorPosition = Rightmotor.position(degrees);

///////////////////////////////////
//Lateral Movement PID
//////////////////////////////////////////////////////
//Get average of the two motors
int averagePosition = (leftMotorPosition + rightMotorPosition)/2;
```

// potential
error = averagePosition - desiredValue;

// derivative
derivative = error - prevError;

```
//code
prevError = error;
vex::task::sleep(20);
```

}
return 1;

}
/*--------------------------------------------------------------------------*/
/* <em>/
/</em> Autonomus Task <em>/
/</em> <em>/
/</em> This task is used to control your robot during the autonomus phase of <em>/
/</em> a VEX Competition. <em>/
/</em> <em>/
/</em> You must modify the code to add your own robot specific commands here. <em>/
/</em>--------------------------------------------------------------------------*/

void autonomous(void) {

vex::task billWiTheScienceFi(drivePID);

/////////////////////////////
//Drivetrain
//Settings
//////////////////////////////////////////////////////////////////////////////

//Driver Control

double turnImportance = 0.5;

while (1) {
/////////////////////////////
//Driver Control
//////////////////////////////////////////////////////////////////////////////

double turnVal = Controller1.Axis1.position(percent);

double forwardVal = Controller1.Axis3.position(percent);

double turnVolts = turnVal * 0.12;
double forwardVolts = forwardVal * 0.12 * (1 - std::abs (turnVolts)/12.0) * turnImportance;

//12 - 12 = 0
//12 + 12= 12 (due to cap)

Leftmotor.spin(forward, forwardVolts + turnVolts, voltageUnits::volt);
Rightmotor.spin(forward, forwardVolts - turnVolts, voltageUnits::volt);
////////////////////////////////////////////////////////////////////////////

/////////////////////////////
//Arm Control
////////////////////////////////////////////////////////////////////////////

bool topRightButton = Controller1.ButtonR1.pressing();
bool bottomRightButton = Controller1.ButtonR2.pressing();

if (topRightButton){
ArmMotor.spin(forward, 12.0, voltageUnits::volt);

}
else if (bottomRightButton){
ArmMotor.spin(forward, 12.0, voltageUnits::volt);

}
else{
ArmMotor.spin(forward, 0, voltageUnits::volt);

}
////////////////////////////////////////////////////////////////////////////

//Claw Control
////////////////////////////////////////////////////////////////////////////

bool topLeftButton = Controller1.ButtonL1.pressing();
bool bottomLeftButton = Controller1.ButtonL2.pressing();

if (topLeftButton){
ClawMotor.spin(forward, 12.0, voltageUnits::volt);

}
else if (bottomLeftButton){
ClawMotor.spin(forward, 12.0, voltageUnits::volt);

}
else{
ClawMotor.spin(forward, 0, voltageUnits::volt);

}

// This is the main execution loop for the user control program
// Each time through the loop your program must update motor + servo
// values based on feedback from the joysticks.

//…
// Insert user code here. This is where you use the joystick values to
// update your motors, etc.
//…

wait(20, msec); // sleep the task for a short amount of time to
// prevent wasted sources
}
#include “vex.h”
using namespace vex;

int (main); {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
Brain.Screen.print(“Hello”);

}

while (1)
wait(20,msec);
int num1 =1;
double num2 = 1.2;
char char1 = ‘A’;
bool bool1 = false;
num1 = (int)num2;
num2 = 3/2.0;
char1 = ‘B’;
bool1 = false;
bool1 = true;

/*==

> =

<
<=
!-*/

while(1==1){
// code
num2 = 2.0;
}

double turnVal = Controller1.Axis1.position(percent);
double forwardVal = Controller1.Axis3.position(percent);
double turnVolts = turnVal *0.12;
double forwardVolts = forwardVal *0.12;

//12 - 12 = 0
//12 + 12= 12 (due to cap)

Leftmotor.spin(forward, forwardVolts - turnVolts, voltageUnits::volt);
Rightmotor.spin(forward, forwardVolts + turnVolts, voltageUnits::volt);

}

Formatted for everyone else.
@leighar23, you can do this by adding a " [code]" and “/code]” at the end.

What do you mean by putting it at the end?

 [code]
Code goes here
[/code]

We just tried that and now it is showing up red. How do we fix that?

Sorry, that might have been confusing. This is just for formatting in the vex forum, don’t do that in your code. sorry for the confusion.

Okay, thank you. We do have an “int main ();” and we do not know what to put in the parentheses.

We’ve already tried searching multiple things up on YouTube, but the same websites keep coming up. Unfortunately, none of them work. We hope to hear from you very soon.

I’m afraid that I can’t help you with that very much- I don’t really do any coding. I’m sorry. I help you get your help soon.

Hello again, we still have a problem with the coding. We still have no ideas on how to fix the exit code 2: error. If you wouldn’t mind could you help us again?

You do not put anything in the parenthesis, only between the curly brackets after the function. In Vexcode (and most C++ programs), when you run a program, anything in the int main function is run. You have to put all of your autonomous code in one function and all of you driver control code in another function above. Then, your int main should look like this:

int main(){

    //auton code goes in autonFunction
    vex::Competition.autonomous(autonFunction);

    //driver control code goes in driverFunction
    vex::Competition.drivercontrol(driverFunction);

    //runs whatever you want in preautonomous
    pre_auton();

}

This setup is know as the Competition Template because it allows the Competition switch to select and run autonomous and driver control in a Competition. Every team using Vexcode uses this setup for their competition code.

1 Like