Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LNK2005: MApiVersion already defined in (projectName).obj

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
dan.norris.25
1670 Views, 3 Replies

LNK2005: MApiVersion already defined in (projectName).obj

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?

3 REPLIES 3
Message 2 of 4

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
in reply to: dan.norris.25

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

thank you

Message 4 of 4
bob_macallister
in reply to: Anonymous

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>

 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report