LNK2005: MApiVersion already defined in (projectName).obj

LNK2005: MApiVersion already defined in (projectName).obj

dan.norris.25
Contributor Contributor
2,609 Views
3 Replies
Message 1 of 4

LNK2005: MApiVersion already defined in (projectName).obj

dan.norris.25
Contributor
Contributor

I have an MPxNode and an MPxCommand in a plugin I can't compile due to three LNK2005 errors.

 

1>pluginMain.obj : error LNK2005: DllMain already defined in UVDeformer.obj
1>pluginMain.obj : error LNK2005: MApiVersion already defined in UVDeformer.obj
1>pluginMain.obj : error LNK2005: "struct HINSTANCE__ * MhInstPlugin" (?MhInstPlugin@@3PEAUHINSTANCE__@@EA) already defined in UVDeformer.obj

 

I have cmake and my project set up the same way I normally would but this is the first time I've tried to put two tools(node and command) into the same plug-in. What would I need to change to keep these things from writing to the .obj twice?

0 Likes
Accepted solutions (1)
2,610 Views
3 Replies
Replies (3)
Message 2 of 4

dan.norris.25
Contributor
Contributor
Accepted solution

I figured this out one. 
I was including MFnPlugin.h to a source file as well as the pluginMain.cpp

Message 3 of 4

Anonymous
Not applicable

I met the same problem, I wonder how you solved it?

thank you

0 Likes
Message 4 of 4

bob_macallister
Community Visitor
Community Visitor

Thread necro so people in the future know how to solve this.

 

The error results from including "MFnPlugin.h" in multiple translation units. I.e. you have more than one .cpp file which, directly or indirectly, includes this header. Most header files exclusively make symbol declarations. This one however unusually contains a symbol definition: PLUGIN_EXPORT char MApiVersion[] = #_versionThis makes it unsafe to include in multiple translation units resulting in a multiple symbol definition (LNK2005).

 

To fix this error, either:

  1. remove all but one include to "MFnPlugin.h" across your module. This includes your module's pre-compiled header, if it has one.
  2. if this is not possible or is undesired, preprocessor define MNoVersionString before including the file in all but one location across your module:

 

#define MNoVersionString
#include <maya/MFnPlugin.h>

 

 

 

 

0 Likes