Does pre-compilation control work in vex-code pre4.0

Here is my directory …
image

I’m using “extern” to access global variables and “#ifndef, #define, #endif” to oprate pre-compilation…

Here are my codes:

//vex.h
#ifndef _VEX_H_
#define _VEX_H_
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "v5.h"
#include "v5_vcs.h"
using namespace vex;
#endif
//bot.h
#ifndef _BOT_H_
#define _BOT_H_
#include "vex.h"
//declare my brain, controller,  motors, sensors, variables and some functions
#endif
//main.cpp
#include "vex.h"

void pre_auton( void ) {}
extern void autonomous( void );
extern void usercontrol( void );

int main() {
  Competition.autonomous( autonomous );
  Competition.drivercontrol( usercontrol );
  pre_auton();
    
  while(1) {
    vex::task::sleep(100);
  }
}
//usercontrol.cpp
#include "vex.h"
#include "bot.h"
void usercontrol( void ) {
  ...
}
//autonomous.cpp
#include "vex.h"
#include "bot.h"

void autonomous( void ) {
  if(auton == 1) {
  #include "auto1.h"
  }
  if(auton == 2) {
  #include "auto2.h"
  }
//.......
  if(auton == 8) {
  #include "auto8.h"
  }
}

But the Output seems like the program didnt pre-compiled…

image

Hope for a solution, my team and friends have struggled for serveral times…LOL
:sweat_smile:

header guards only stop an include file being used more than once within a specific source file

see this thread that explains how to declare global instances for use by more than one source file.

1 Like

May it is too complex declaring all motors and my funtions in vex.h, is there any way simpler?

Maybe it is too complex declaring all motors and my funtions in vex.h, is there any way simpler?