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?
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?
You’re going to have to be more specific. Is it a linker error?
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:
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.
I feel it’s something with the #include or how I use the functions from different classes or whatever they are called in c++
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?
What preview is this? Preview 2 had an issue where the program would randomly stop compiling and the fix was to restart the application.
No, that’s when I download it, this doesn’t occur as a bug, it’s 99% something I did.
I tried to make it a .cpp, but when I include the cpp, it still gives me the error
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
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.
Could you PM me a .zip file with your code so that I can help you?
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!
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?
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;
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?
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:
Sorry, I don’t have much time to help people with their code, since I’m trying to rewrite a lot of my code.