I have a function define in a header that I want to use in multiple modules of the same plug in, but when I try to use it I got compile error, “multiple definition”.
moving the #include to plugin.cpp, moving it to plugin.hpp, etc…
I have even tried to put the header in the sdk include file, which works as long as I use the function in only one module
The header is protected with #pragma once and #ifndef
I may have made an error in c++, I’m pretty new to all of this, still struggling to understand everything about the linkers
Any ideas ?
(I’m on windows, compiling with Mingw64, apart from this, everything is working fine)
If your header file contains an implementation of the function, then you should not include it in multiple source files.
In the other thread that you linked, the header file has a mechanism using a #define to control whether it is included with an implementation or not. If your header has a mechanism like this, you need to ensure that exactly one of your source files includes the implementation.
With dr wave you can include it everywhere, but there is a define for the implementation that can only be in one file. I use this in my SFZ player, it works fine.
It was juste an example, it was the closest thread I have found,
The header contain few tools that I have made and often use, for example mapping a value from -5/+5 to 0/10 (or any other values)
I have tried with inline, it works, but I don’t know if it won’t create more problem in the long run
You can put the functions in a separate cpp file, and just put the function declarations in the header file. Then the linker will just find one definition/implementation.
Or you can wrap the function in an anonymous namespace. Then each source file that includes the header will get a unique version of the function, and the linker won’t complain about duplicates.