Make: *** [vex/mkrules.mk:13: build/src/main.o] Error 1, i don't know why this error is appearing

This error message is only appearing after I moved my teams driver control code into the competition template but it doesn’t happen in it’s own individual file. the error is showing for the curly brace just after void finesse() and just after int main().

here is the error message

[info]: Saving Project …

[info]: Project saved!

windows build for platform vexv5

“CXX src/main.cpp”

src/main.cpp:88:1: error: function definition is not allowed here

{

^

src/main.cpp:101:12: error: function definition is not allowed here

int main() {

^

2 errors generated.

make: *** [vex/mkrules.mk:13: build/src/main.o] Error 1

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

below here is the code for the robot, only worry about the driver control section I copy pasted it all just in case.

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

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// FR                   motor         10              
// FL                   motor         1               
// BR                   motor         9               
// BL                   motor         2               
// Controller1          controller                    
// ---- 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) {
  // ..........................................................................
  // 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) {
    // This is the main execution loop for the user control program.
    // Each time through the loop your program should update motor + servo
    // values based on feedback from the joysticks.

int X2 = 0;
int Y1 = 0;
int X1 = 0;
int threshold = 10;
int F = 0;

void finesse()
{
  if (F==0)
  {
    F = 1;
  }
  else
  {
    F = 0;
  }
}
  


int main() {
  vexcodeInit();
  Controller1.ButtonLeft.pressed(finesse);

while (1)
{

  float Ch1 = Controller1.Axis1.position();
  float Ch2 = Controller1.Axis2.position();
  float Ch3 = Controller1.Axis3.position();
  float Ch4 = Controller1.Axis4.position();
  
  if(fabs(Ch2) > threshold)
  {
    Y1 = Ch2;
  }
  else
  {
    Y1 = 0;
  }
    if(fabs(Ch1) > threshold)
  {
    X1 = Ch1;
  }
  else
  {
    X1 = 0;
  }
    if(fabs(Ch4) > threshold)
  {
    X2 = Ch4;
  }
  else
  {
    X2 = 0;
  }
  if (F==1)
  {
    FR.spin(fwd, .5*(Y1-X2-X1), pct);
    BR.spin(fwd, .5*(Y1-X2+X1), pct);
    FL.spin(fwd, .5*(Y1+X2+X1), pct);
    BL.spin(fwd, .5*(Y1+X2-X1), pct);
  }
  else
  {
    FR.spin(fwd, Y1-X2-X1, pct);
    BR.spin(fwd, Y1-X2+X1, pct);
    FL.spin(fwd, Y1+X2+X1, pct);
    BL.spin(fwd, Y1+X2-X1, pct);
  }
 }
} 


    wait(20, msec); // 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);
  }
}

edit: code tags added by mods

probably mis-matched braces, check that every opening “{” you have a closing “}”.

and you have two main functions, that won’t help.

6 Likes

Getting rid of the first main function got rid of the error next to it, but the first error next to my void function is still there. I’ve double checked that all my braces are closed properly but the error is still there. Thank you for helping with one of them still!