VEXcode compiles with no problems but can’t build

#1

Basically I am trying to use multiple files for my program, when I try to build it tho, it gives me
make process closed with exit code : 2

Any ideas anyone?

0 Likes

#2

You’re going to have to be more specific. Is it a linker error?

0 Likes

#3

When I press the build button, it starts building it I’m guessing, I’m more a java guy so I learn c++ as I go, but in the end it gives me that error and it looks like this:
image

0 Likes

#4

It looks to me like you’re defining vars in header files. Try defining there variables in source files and instead using the extern keyword to put these in the headers.

0 Likes

#5

I feel it’s something with the #include or how I use the functions from different classes or whatever they are called in c++

0 Likes

#6

So header files are the .h? One of my .h files has the full robot config, like vex::brain or vex::controller… should I make it cpp?

0 Likes

#7

What preview is this? Preview 2 had an issue where the program would randomly stop compiling and the fix was to restart the application.

0 Likes

#8

No, that’s when I download it, this doesn’t occur as a bug, it’s 99% something I did.

0 Likes

#9

I tried to make it a .cpp, but when I include the cpp, it still gives me the error

0 Likes

#10

Dont include the .cpp. Instead, continue including the header, but have the variable definitions in the .cpp and the extern definitions in the header. Ex:

main.cpp:

#include "myvariable.h"
#include <iostram>

int main {
    std::cout<<myvariable<<std::endl;
}

myvariable.cpp:

#include "myvariable.h"

int myvariable = 7;

myvariable.h:

extern int myvariable;

This should print the number 7 to the terminal

0 Likes

#11

The only .h files that I have is the vex.h and robot-config.h, robot config includes vex.h and iostream and has all the vex::brain stuff.
The normal cop files include the config and vex.h. Any function that I use in another file, I declare with the first line of the function. Idk what’s wrong.

0 Likes

#12

Could you PM me a .zip file with your code so that I can help you?

0 Likes

#13

Yes, I want to, idk if I could because my WiFi is out so I’m texting from my phone, I will try to get the files on the phone dm you from here, thank you!

0 Likes

#14

I’m having a similar problem but for PROS, basically I have all my files confused. My source files and header files are all out of wack. Can I pm you my repository on Git and you take a look at it?

0 Likes

#15

So basically, apart from your vex.h, you should have a robotconfig.h file. After you have the .h, make another file called robotconfig but with extention .cpp. Your robotconfig.h should have everything identical, plus, before each vex::brain, vex::controller etc, you add extern.

robotconfig.h

#include “vex.h”
#include <iostream>

 extern vex::brain Brain;

robotconfig.cpp

#include “vex.h”
#include <iostream>

vex::brain Brain;

Basically a copy of it but with extern.

In addition to all that, every variable that you use in multiple files, should have a declaration in one of them -int auton = 4; , and all others should beextern int auton;

0 Likes

#16

Can someone just clarify what goes in header files and what goes in source files. Also, is it good practice to make a header file for each source file you make or can you just make one header file that includes all the source files?

0 Likes

#17

From what I understand, there should be less headers than sources, don’t take my word for it.

These are some links to videos about all of that stuff:

I suggest you watch this playlist:




0 Likes

#18

Sorry, I don’t have much time to help people with their code, since I’m trying to rewrite a lot of my code.

0 Likes