I’m working on an autonomous selector and I’m not sure why pros is giving me this error: “undefined reference to `VIS::S::Auton::Auton(char const*, char const*, std::function<void ()>)”. In the code, this is a class that I created with inline (extern didn’t work either) in a .hpp file that is included, I’m not sure why this is showing up because it’s included, used only after the include, and clangd does not give an error.
The definition is in a .hpp file because other parts of the selector use it and it needs to be defined for those files.
The error occurs in: main.cpp (line 20)
The definition is in: include/Visual VEX/VISUAL_API.hpp (line 4)
The class is defined in: include/Visual VEX/namespace.hpp (line 60)
This is a wierd error. I’m not sure as to whats happening, but I do think you might be able to avoid it by making auton_selector a singleton class or maybe a namespace?
That sounds like you have a declaration of the class without defining an instance. “inline” isn’t usually used this way, it’s intended to move code for small functions into the code where they are called…
I’ve got everything defined; now, I just need to redefine a class initializer that is protected by #pragma once. I’ve updated the Beta branch on the GitHub link.
Don’t forget that this is not project wide, it just stops the pre-processor including a header more than once when compiling a single file, just an alternative for the more traditional header guards.
I now have this code, getting the same error. Not fully sure why, from what I know, this should run and define “API_RUN_ONCE” and “auton_selector” next time the file is included, #ifndef should not allow the redef of “auton_selector” because it will be false due to “API_RUN_ONCE” being defined.
Its code at the bottom of include\Visual VEX\VISUAL API.hpp
yea, this should not be in a header file, unless it’s included once and only once in the project. Every time the header is included somewhere it will try and define that global. As I said in the last post, #pragma once or headers guards will not help.
I now have the definition not in a header. The functions that reference “auton_selector” have been moved to a consistent file where “auton_selector” is defined, which is in a C++ file.
I now have a similar error, closer to why this thread was made, that tells me all the functions for displaying are defined in my namespace file, but lack an instance. I still have a file with all the code for those functions that should make the instance; the compiler just seems to be “blind” to them, or I’m missing a crucial part that tells the header where the instances are.