-SEMI-SOLVED- [DYNRPG] "MULTIPLE DEFINITION OF 'RPG::*'" ERROR
Posts
Pages:
1
I'm having trouble trying to implement a plugin involving multiple classes spread across multiple source files. The problem is, when I try to compile, I get the error message and 49 other very similar errors. It would appear this is happening because several different header files have in them, but I would have thought that the compiler directive in DynRPG.h would protect it from being redefined. Trying to only use the #include "DynRPG/DynRPG.h" directive in one file doesn't seem to work very well either, as I get in any files for which I try to use DynRPG stuff without having the #include. Has anybody else run into this before and figured out how to fix or work around it?
multiple definition of 'RPG::Variables::name(int)'
#include "DynRPG/DynRPG.h"
#ifndef DYNRPG_H
error: 'RPG' has not been declared
Okay, I did some more research and it turns out that this is actually a relatively common C++ problem. I found a fairly good article about it here (it's the "SECOND QUESTION" in the article), although it doesn't explain terribly well what to do about it. This article is a little more explicit about how to do it right, in the section "Function inlining".
The basic idea, as I understand it, is that while include guards (like #ifndef DYNRPG_H) will prevent multiple definitions of something in one source (.cpp) file, if you try to include the same header file in more than one source file in a project, each one will be compiled separately before attempting to link them together, causing potential redefinitions. If you want to have a header file that multiple separate source files use, you're apparently supposed to use the keyword "inline" on function and variable definitions. Of course, if I'm reading this right, that means it's a fix that would have to be made to DynRPG itself. I'm not even sure that would be the right approach, maybe if separate source files referencing DynRPG.h could compile and be linked together in a single plugin they'd try to each have their own instance of the RPG class, and that would definitely be bad (although considering separate plugins all manage to somehow share the RPG class and its methods...eh, I dunno how it all works).
At any rate, the solution I'm going to try from here is to only use one main source file for my plugin, and have header files that completely implement their respective classes. A bit unorthodox, but I don't know of any reason why it shouldn't work.
The basic idea, as I understand it, is that while include guards (like #ifndef DYNRPG_H) will prevent multiple definitions of something in one source (.cpp) file, if you try to include the same header file in more than one source file in a project, each one will be compiled separately before attempting to link them together, causing potential redefinitions. If you want to have a header file that multiple separate source files use, you're apparently supposed to use the keyword "inline" on function and variable definitions. Of course, if I'm reading this right, that means it's a fix that would have to be made to DynRPG itself. I'm not even sure that would be the right approach, maybe if separate source files referencing DynRPG.h could compile and be linked together in a single plugin they'd try to each have their own instance of the RPG class, and that would definitely be bad (although considering separate plugins all manage to somehow share the RPG class and its methods...eh, I dunno how it all works).
At any rate, the solution I'm going to try from here is to only use one main source file for my plugin, and have header files that completely implement their respective classes. A bit unorthodox, but I don't know of any reason why it shouldn't work.
Pages:
1













