VSTGUI 4.5: Linker error LNK2005 xyz already defined

DSP, Plug-in and Host development discussion.
EagleEye
KVRist
98 posts since 25 Apr, 2002

Post Sun Apr 08, 2018 11:57 am

Hi all

I'm having a hard time ...
I try to create a new simple plugin using vst 2.4 rev2 and vstgui 4.5 on Windows 10. I have some experience using vstgui 3.6. I have to admit that my C++ skills are rather limited, to be honest ...
The tutorials don't really help.

My project compiles fine, but I get lots of Linker errors LNK2005, like
LNK2005 "public: __cdecl VSTGUI::Animation::AlphaValueAnimation::AlphaValueAnimation(float,bool)" (??0AlphaValueAnimation@Animation@VSTGUI@@QEAA@M_N@Z) ist bereits in animations.obj definiert. StereoDelay_2018_1 C:\VisualStudio2017\StereoDelay_2018_1\StereoDelay_2018_1\vstgui.obj 1
I included all the the files from the vstgui root folder except for standalone, mac and linux. In addition I added the subfolder lib and its subfolders animation, controls and platform.
Screenshot.png
I'm aware that this might not be enough information. I also tried to find the additional definition/includes, but couldn't find them.

Can anyone shed some light on this?
Thanks in advance!
You do not have the required permissions to view the files attached to this post.
Image

User avatar
syntonica
KVRist
443 posts since 25 Sep, 2014 from Specific Northwest

Re: VSTGUI 4.5: Linker error LNK2005 xyz already defined

Post Tue Apr 10, 2018 2:59 pm

Multiple defines happen when header files are not gated and get loaded twice. You'll also run into this if you have a mix of C, C++ and whatever else your compiler will look at. My code is a mix of C, C++, Objective-C and Objective-C++, so I have to double-check everything to make sure for each object file that's being compiled, it's not pulling the same headers twice (or more). Incomplete class definitions can help as well as using void pointers or passing needed pointers to get out of tricky situations. Unfortunately, my code has its hands in each other's pockets.

I hope this helps. I haven't used VSTGUI, so am unfamiliar with any pitfalls.

mystran
KVRAF
5035 posts since 12 Feb, 2006 from Helsinki, Finland

Re: VSTGUI 4.5: Linker error LNK2005 xyz already defined

Post Tue Apr 10, 2018 3:23 pm

syntonica wrote:Multiple defines happen when header files are not gated and get loaded twice.
If you get a linker error (rather than a compiler error) for multiple definitions, then that means the same function was compiled into multiple object files (ie. as part of multiple source files). This is usually not a header-guard issue, but rather a problem with functions being defined in the headers. One can get around this by using "static" qualifier (eg. for "inline" functions that you obviously want to define in headers, but which might still generate linking issues if the compiler opts not to inline them; the downside is that you might end up with multiple copies in the binary).

The exception to this rule is C++ methods defined inside the class-definition. For these, the standard requires that if the compiler generates multiple copies (ie. if it's unable to inline them everywhere), the linker is required to just pick one and discard the rest (and you should expect "undefined behavior" if you use pre-processing magic to make the copies different from each other).
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

User avatar
syntonica
KVRist
443 posts since 25 Sep, 2014 from Specific Northwest

Re: VSTGUI 4.5: Linker error LNK2005 xyz already defined

Post Tue Apr 10, 2018 8:54 pm

mystran wrote: This is usually not a header-guard issue, but rather a problem with functions being defined in the headers.
Thank you for correcting me. Functions or pretty much any define. I run into it especially with mixed-language compiles and reading macOS Cocoa.h more than once. I'm really beginning to dislike header-only libraries. At first, I thought they were neat, but they cause me more trouble...

I'm still learning about modern compilers. I just discovered you can use a #pragma to define the library you're linking to. Less faffing about in the IDE. And the options are just mind-boggling to me anymore...

I miss the old days of C with one header and one code. Unfortunately, I do like my classes...

Unfortunately, none of my babbling is probably helping the OP. Sorry.

User avatar
noizebox
KVRer
28 posts since 19 Nov, 2012 from Stockholm, Sweden

Re: VSTGUI 4.5: Linker error LNK2005 xyz already defined

Post Wed Apr 11, 2018 12:21 am

EagleEye wrote:I included all the the files from the vstgui root folder except for standalone, mac and linux. In addition I added the subfolder lib and its subfolders animation, controls and platform.
Do you mean include as in #include <> or just included them in the project include folders? I'm thinking that perhaps you're including the .cpp files from vstgui in you build (which would cause your build to contain definitions of vstgui functions) and then linking against the vstgui library which would cause a multiple definitions error.

The normal way of including libraries is to include the header files in your project (so you have the declarations) and then link your compiled code against the library, which holds the function definitions.

EagleEye
KVRist
98 posts since 25 Apr, 2002

Re: VSTGUI 4.5: Linker error LNK2005 xyz already defined

Post Thu Apr 12, 2018 3:19 am

Thank you guys for your help.
Do you mean include as in #include <> or just included them in the project include folders?
No, sorry. This is/was misleading, my bad. I only include aeffguieditor.h in the headerfile of my editor - nothing else. This worked perfectly with VSTGUI 3.6

Code: Select all

// Old VSTGUI 3.6
// #include "../vstgui/aeffguieditor.h"

// New VSTGUI 4.5
#include "../vstgui/plugin-bindings/aeffguieditor.h"
Other than that I didn't change anything, taking over the file structure as it is and importing it into my Visual Studio project.
Image

Return to “DSP and Plug-in Development”