*Error* "Make process closed with Exit Code: 2" unknown cause of error

#include “vex.h”

using namespace vex;

int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();

// /----------------------------------------------------------------------------/
// /* /
// /
Module: main.cpp /
// /
Author: {author} /
// /
Created: {date} /
// /
Description: V5 project /
// /
/
// /
----------------------------------------------------------------------------/
// #include “vex.h”
//
// // ---- START VEXCODE CONFIGURED DEVICES ----
// // Robot Configuration:
// // [Name] [Type] [Port(s)]
// // ---- END VEXCODE CONFIGURED DEVICES ----
//
// using namespace vex;
//
// // A global instance of vex::brain used for printing to the V5 brain screen
vex::brain Brain;
vex::competition Competition;
vex::controller Controller1;
vex::motor LeftMotor = vex::motor( vex::PORT10 );
vex::motor RightMotor = vex::motor( vex::PORT1, true );
vex::motor LeftMotorB = vex::motor( vex::PORT9 );
vex::motor RightMotorB = vex::motor( vex::PORT2, true );
vex::motor ClawR = vex::motor( vex::PORT5 );
vex::motor ArmR = vex::motor( vex::PORT4 );
vex::motor ArmL = vex::motor( vex::PORT7, true );
// // A global instance of vex::competition
//
//
// // define your global instances of motors and other devices here
//
//
// /
---------------------------------------------------------------------------/
// /
Pre-Autonomous Functions /
// /
/
// /
You may want to perform some actions before the competition starts. /
// /
Do them in the following function. You must return from this function /
// /
or the autonomous and usercontrol tasks will not be started. This /
// /
function is only called once after the cortex has been powered on and /
// /
not every time that the robot is disabled. /
// /
---------------------------------------------------------------------------/
//
// void pre_auton( void ) {
// // All activities that occur before the competition starts
// // Example: clearing encoders, setting servo positions, …
//
// }
//
// /
---------------------------------------------------------------------------/
// /
/
// /
Autonomous Task /
// /
/
// /
This task is used to control your robot during the autonomous phase of /
// /
a VEX Competition. /
// /
/
// /
You must modify the code to add your own robot specific commands here. /
// /
---------------------------------------------------------------------------/
//
void autonomous( void ) {
RightMotor.setVelocity(100, velocityUnits::pct);
RightMotor.spin(vex::directionType::rev);
RightMotorB.setVelocity(100, velocityUnits::pct);
RightMotorB.spin(vex::directionType::rev);
LeftMotor.setVelocity(100, velocityUnits::pct);
LeftMotor.spin(vex::directionType::rev);
LeftMotorB.setVelocity(100, velocityUnits::pct);
LeftMotorB.spin(vex::directionType::rev);
vex::task::sleep(1500);
RightMotor.stop(vex::brakeType::brake);
RightMotorB.stop(vex::brakeType::brake);
LeftMotor.stop(vex::brakeType::brake);
LeftMotorB.stop(vex::brakeType::brake);
RightMotor.setVelocity(100, velocityUnits::pct);
RightMotor.spin(vex::directionType::rev);
RightMotorB.setVelocity(100, velocityUnits::pct);
RightMotorB.spin(vex::directionType::rev);
LeftMotor.setVelocity(100, velocityUnits::pct);
LeftMotor.spin(vex::directionType::rev);
LeftMotorB.setVelocity(100, velocityUnits::pct);
LeftMotorB.spin(vex::directionType::rev);
vex::task::sleep(1500);
RightMotor.stop(vex::brakeType::brake);
RightMotorB.stop(vex::brakeType::brake);
LeftMotor.stop(vex::brakeType::brake);
LeftMotorB.stop(vex::brakeType::brake); // …
// // Insert autonomous user code here.
// // …
//
}
//
// /
---------------------------------------------------------------------------/
// /
/
// /
User Control Task /
// /
/
// /
This task is used to control your robot during the user control phase of /
// /
a VEX Competition. /
// /
/
// /
You must modify the code to add your own robot specific commands here. /
// /
---------------------------------------------------------------------------*/
//
void usercontrol( void ) {
// User control code here, inside the loop
while (1) {
LeftMotor.spin(vex::directionType::fwd, Controller1.Axis3.position(), vex::velocityUnits::pct);
RightMotor.spin(vex::directionType::fwd, Controller1.Axis2.position(), vex::velocityUnits::pct);
LeftMotorB.spin(vex::directionType::fwd, Controller1.Axis3.position(), vex::velocityUnits::pct);
RightMotorB.spin(vex::directionType::fwd, Controller1.Axis2.position(), vex::velocityUnits::pct);
ArmR.setVelocity(100, velocityUnits::pct);
ArmL.setVelocity(100, velocityUnits::pct);
ArmR.spin(vex::directionType::fwd, Controller1.ButtonR2.pressing(), vex::velocityUnits::pct);
ArmL.spin(vex::directionType::fwd, Controller1.ButtonR2.pressing(), vex::velocityUnits::pct);
ArmR.spin(vex::directionType::rev, Controller1.ButtonR1.pressing(), vex::velocityUnits::pct);
ArmL.spin(vex::directionType::rev, Controller1.ButtonR1.pressing(), vex::velocityUnits::pct);
if(Controller1.ButtonL2.pressing()){
ClawR.spin(vex::directionType::fwd);
}
else{
if (Controller1.ButtonL1.pressing()){
ClawR.spin(vex::directionType::rev);
}
else{
ClawR.stop(brakeType::brake);
vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources.
}
}
}

I don’t know what your question is but you might want to take a look at that double ‘else’ statement at the end of your usercontrol

the error was with the brackets after void usercontrol ( void )
and void autonomous ( void )

i also recieve a “make process closed with exit code: 2” error in the build menu

well unless you are going to send us the full error message I can only assume that fixing that double else statement will fix the error. Just because it says the error is with the brackets doesn’t mean the brackets are necessarily the problem.

here is the text from the build menu “[info]: Project Path: C:\Users\joe\Documents\vexcode-projects\MyProject5
[info]: Upgrading project…
[info]: Project backed up to C:\Users\joe\Documents\vexcode-projects\MyProject5\backup
[info]: Updating device configuration…
[info]: Device configuration inserted few comments in the file: src/main.cpp
[info]: Saving Files - include/robot-config.h, include/vex.h, src/robot-config.cpp
[info]: Saved : include/robot-config.h, include/vex.h, src/robot-config.cpp
[info]: Done upgrading project
[info]: Saving Project …
[info]: Project saved!
windows build for platform vexv5
“CXX src/main.cpp”
src/main.cpp:160:10: warning: empty parentheses interpreted as a function declaration [-Wvexing-parse]
int main() ;
^~
src/main.cpp:160:10: note: replace parentheses with an initializer to declare a variable
int main() ;
^~
= 0
1 warning generated.
“CXX src/robot-config.cpp”
“LINK build/MyProject5.elf”
build/src/main.o: In function main': main.cpp:(.text.main+0x404): undefined reference to autonomous()’
main.cpp:(.text.main+0x408): undefined reference to autonomous()' main.cpp:(.text.main+0x414): undefined reference to usercontrol()’
main.cpp:(.text.main+0x41c): undefined reference to usercontrol()' C:\Program Files (x86)\VEX Robotics\VEXcode V5 Text\sdk/vexv5\libv5rt.a(vex_competition.cpp.obj): In function vex::competition::competition()’:
(.text._ZN3vex11competitionC2Ev+0x11c): undefined reference to autonomous()' C:\Program Files (x86)\VEX Robotics\VEXcode V5 Text\sdk/vexv5\libv5rt.a(vex_competition.cpp.obj): In function vex::competition::competition()’:
(.text._ZN3vex11competitionC2Ev+0x120): undefined reference to `usercontrol()’
make: *** [vex/mkrules.mk:18: build/MyProject5.elf] Error 1
[error]: make process closed with exit code : 2
[info]: Saving Project …
[info]: Project saved!
windows build for platform vexv5
“CXX src/main.cpp”
src/main.cpp:89:26: error: function definition is not allowed here
void autonomous( void ) {
^
src/main.cpp:131:27: error: function definition is not allowed here
void usercontrol( void ) {
^
2 errors generated.
make: *** [vex/mkrules.mk:13: build/src/main.o] Error 1
[error]: make process closed with exit code : 2”

ah I see the problem. You didn’t need to put the whole template into ‘int main’. The error you get is because you are defining functions inside a function definition.

EDIT: to elaborate, the competition template should already have a main function - all you have to do is add your code into the ‘usercontrol’ and ‘autonomous’ functions.

1 Like

so i should place the int main only over the “vexcode Init”

No, main is already defined at the bottom of the template. It’ll look like this:

int main() {
  // Set up callbacks for autonomous and driver control periods.
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);

  // Run the pre-autonomous function.
  pre_auton();

  // Prevent main from exiting with an infinite loop.
  while (true) {
    wait(100, msec);
  }
}

You shouldn’t have to add or move any function definitions aside from custom functions.
The template automatically calls usercontrol and autonomous functions when the program runs, so there’s no need to change it.

1 Like

i have no added definitions or int main() { placed in the code

Also, disregard my comment about your else statements - the formatting confused me a bit but it does make sense now that I put your code into vexcode

after i placed the int main() brackets only around the vexcode Init the error was removed from the void usercontrol and the void Autonomous but placed on the bracket by the int main() at the bottom

I’m not too sure how exactly you set up your file, but ‘int main’ isn’t supposed to be there.

In your initial post int main was missing its end bracket so the program thought your whole file was the main function.

If you ask me the fastest solution to this would be to open the competition template again and just copy-paste your personal ‘usercontrol’ and ‘autonomous’ functions back in.

1 Like

also the int main() {
vexcodeInit();
}
was placed there in the template it gave me

i copied and pasted and the errors dissapeared but it gave me the “make process closed with exit code: 2” error once again

here is the new code

Ah, I see what happened. The competition template isn’t supposed to be copied into the file you get at startup - it functions by itself.

So by opening the competition template and pasting in the code that you made, I got this:
If you want you can copy this but it’s good to figure out what happened first.

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       VEX                                                       */
/*    Created:      Thu Sep 26 2019                                           */
/*    Description:  Competition Template                                      */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

// A global instance of competition
competition Competition;

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

/*---------------------------------------------------------------------------*/
/*                          Pre-Autonomous Functions                         */
/*                                                                           */
/*  You may want to perform some actions before the competition starts.      */
/*  Do them in the following function.  You must return from this function   */
/*  or the autonomous and 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 activities that occur before the competition starts
  // Example: clearing encoders, setting servo positions, ...
}

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

void autonomous( void ) {
RightMotor.setVelocity(100, velocityUnits::pct);
RightMotor.spin(vex::directionType::rev);
RightMotorB.setVelocity(100, velocityUnits::pct);
RightMotorB.spin(vex::directionType::rev);
LeftMotor.setVelocity(100, velocityUnits::pct);
LeftMotor.spin(vex::directionType::rev);
LeftMotorB.setVelocity(100, velocityUnits::pct);
LeftMotorB.spin(vex::directionType::rev);
vex::task::sleep(1500);
RightMotor.stop(vex::brakeType::brake);
RightMotorB.stop(vex::brakeType::brake);
LeftMotor.stop(vex::brakeType::brake);
LeftMotorB.stop(vex::brakeType::brake);
RightMotor.setVelocity(100, velocityUnits::pct);
RightMotor.spin(vex::directionType::rev);
RightMotorB.setVelocity(100, velocityUnits::pct);
RightMotorB.spin(vex::directionType::rev);
LeftMotor.setVelocity(100, velocityUnits::pct);
LeftMotor.spin(vex::directionType::rev);
LeftMotorB.setVelocity(100, velocityUnits::pct);
LeftMotorB.spin(vex::directionType::rev);
vex::task::sleep(1500);
RightMotor.stop(vex::brakeType::brake);
RightMotorB.stop(vex::brakeType::brake);
LeftMotor.stop(vex::brakeType::brake);
LeftMotorB.stop(vex::brakeType::brake); // …
// // Insert autonomous user code here.
// // …
//
}
//
// /---------------------------------------------------------------------------/
// / /
// / User Control Task /
// / /
// / This task is used to control your robot during the user control phase of /
// / a VEX Competition. /
// / /
// / You must modify the code to add your own robot specific commands here. /
// /---------------------------------------------------------------------------*/
//
void usercontrol( void ) {
// User control code here, inside the loop
while (1) {
LeftMotor.spin(vex::directionType::fwd, Controller1.Axis3.position(), vex::velocityUnits::pct);
RightMotor.spin(vex::directionType::fwd, Controller1.Axis2.position(), vex::velocityUnits::pct);
LeftMotorB.spin(vex::directionType::fwd, Controller1.Axis3.position(), vex::velocityUnits::pct);
RightMotorB.spin(vex::directionType::fwd, Controller1.Axis2.position(), vex::velocityUnits::pct);
ArmR.setVelocity(100, velocityUnits::pct);
ArmL.setVelocity(100, velocityUnits::pct);
ArmR.spin(vex::directionType::fwd, Controller1.ButtonR2.pressing(), vex::velocityUnits::pct);
ArmL.spin(vex::directionType::fwd, Controller1.ButtonR2.pressing(), vex::velocityUnits::pct);
ArmR.spin(vex::directionType::rev, Controller1.ButtonR1.pressing(), vex::velocityUnits::pct);
ArmL.spin(vex::directionType::rev, Controller1.ButtonR1.pressing(), vex::velocityUnits::pct);
if(Controller1.ButtonL2.pressing()){
ClawR.spin(vex::directionType::fwd);
}
else{
if (Controller1.ButtonL1.pressing()){
ClawR.spin(vex::directionType::rev);
}
else{
ClawR.stop(brakeType::brake);
vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources.
}
}
}
}
//
// Main will set up the competition functions and callbacks.
//
int main() {
  // Set up callbacks for autonomous and driver control periods.
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);

  // Run the pre-autonomous function.
  pre_auton();

  // Prevent main from exiting with an infinite loop.
  while (true) {
    wait(100, msec);
  }
}
1 Like

The whole code? you might just have to type something else in for the IDE to actually check your code…

What is the IDE? is that a function in the text

Oh, sorry. IDE stands for Integrated development environment, vexcode is an IDE for C++. It just means that the software checks your code for errors. Here’s the wikipedia page on IDEs:

Essentially what I meant is that the software might not have checked your code for errors yet.

1 Like