Hello, I am looking for help on how to use multiple source files for my VEX IQ project. I want to extract some functions related to the drivetrain into their own file, like I would with one of my hobby C++ projects. However, I am getting multiple definition errors like the following:
build/src/Maneuvers.o:(.bss.BlockMotor+0x0): multiple definition of `BlockMotor’ build/src/main.o:(.bss.BlockMotor+0x0): first defined here
If I have the header file that is defining the function included in two different files. I have tried using both the “pragma once” macro and the “ifndef MYHEADER_H…” macros that normally prevent header files from being included twice, but neither of them seem to prevent the error.
Is there any special VEX macro that can be used or something? I am wondering of the compiler used on my code is a more outdated g++ compiler or one without the feature to prevent double-header inclusions.
make sure you include extern (device) of all of the devices you use outside of the file you declared in. You’ll only need to declare it once, your error is indicating that you defined it in main and also in ‘maneuvers’
Also rn this thread’s category is for IQ, this is an EDR discussion.
I’ve tried using the extern, but it seems to give the same error. I understand that the error indicates that I am defining the devices multiple times, but I have only defined them once in their own separate header file. The issue only seems to come up when add more header/cpp files that main includes. If I put all the code from the cpp files into the header files and set up the includes in a way where it no headers are included in main twice, then it compiles.
The error seems to come up whenever I include the line
or if I include the shared header file directly, inside of my Driving.cpp file. If that line is not there, then the error does not show up.
How are you using extern then? It should just be extern devicetype devicename; without any params. I’m having trouble understanding exactly what’s happening without the code, if it isn’t a problem with you can you export your project so we can see all of the files?
EDIT: I need to update vexcode, I don’t usually use this pc for coding, it’s running on version 0.9 or something… so there absolutely are flaws in the comments below for the time being
I’m not sure where setTurnVelocity and setDriveVelocity is declared so I can’t really help there.
stating functions as in driving.h should be in whatever file that the functions are called.
I’m going to dm you my code just as an example because I don’t think I have a very solid grasp of how your code works. You’ll see that I’ve defined my functions, variables and devices in .cpp files and then extern is all in my .h files.
Okes so you can pretty much ignore my previous post, a lot of the errors were solved by updating vexcode
All of the errors I found were solved by copying the function statements in driving.h to maneuvers.h (or just including the file works). Looks like you set everything up alright, but you just forgot to include your functions into maneuvers.h.
The source code for your project that you showed me helped a lot! Turns out I needed to put the externs in the PortConfig.h file, and DEFINE them in a PortConfig.cpp file. I didn’t have one previously. Thank you for the help.