Page 1 of 1

Error Building a Plug-In in Visual Studio

Posted: Thu Oct 26, 2017 2:06 pm
by pittpanther13
Hi all,

I am not too familiar with building user Plug-ins in OpenSim, but I am interested in incorporating a SpineBushing element, which is available on SimTK, into my model. Right now, I am getting a build error in Visual Studio - "LNK1112: module machine type 'x64' conflicts with target machine type 'x86'". I have found many tips online to get rid of this error but have had no luck. Any help would be appreciated and I have attached the files I am currently using.

I have downloaded the following:

CMake
VS 2013 Express (I read that this was the necessary version for OpenSim 3.3)

I have edited the source code offered on SimTK to replicate the API from an example provided in OpenSim 3.3 (BodyDragForce) and have followed directions on the SimTK Confluence site for creating a plugin. It's possible that I am not using the correct generator on CMake, I have tried Visual Studio 12 2013 and Visual Studio 12 2013 Win64.

Thanks a lot,
Ryan

Re: Error Building a Plug-In in Visual Studio

Posted: Thu Oct 26, 2017 2:38 pm
by chrisdembia
Can you post any other output from Visual Studio? The issue is likely that you are trying to build the plugin as 32-bit (x86) but you have a 64-bit copy of OpenSim. Post the contents of the buildinfo.txt file inside OpenSim's installation (in the sdk folder I think). Does it say 32-bit or 64-bit?

If OpenSim is 64-bit, then you want to use the Visual Studio 12 2013 Win64 generator in CMake.

Do you only have one copy of OpenSim installed on your computer?

Re: Error Building a Plug-In in Visual Studio

Posted: Thu Oct 26, 2017 4:26 pm
by pittpanther13
Thanks Christopher, it looks like I did have two versions. For some reason I thought I had been working on the 32-bit but it's actually the 64-bit. My mistake. However, when I compiled the code in CMake using Visual Studio 12 2013 Win64, I then changed everything to x64 in Visual Studio and got the following error.

Code: Select all

1>------ Build started: Project: ZERO_CHECK, Configuration: Release x64 ------
1>  Checking Build System
1>  CMake does not need to re-run because C:/OpenSim 3.3/sdk/APIExamples/Plugins/SpineBushing Source Code2/NewSpineBushing/Binaries15/CMakeFiles/generate.stamp is up-to-date.
2>------ Build started: Project: Libraries - SpineBushingTest, Configuration: Release x64 ------
2>  Building Custom Rule C:/OpenSim 3.3/sdk/APIExamples/Plugins/SpineBushing Source Code2/NewSpineBushing/CMakeLists.txt
2>  CMake does not need to re-run because C:/OpenSim 3.3/sdk/APIExamples/Plugins/SpineBushing Source Code2/NewSpineBushing/Binaries15/CMakeFiles/generate.stamp is up-to-date.
2>  RegisterTypes_osimPlugin.cpp
2>C:\OpenSim 3.3\sdk\APIExamples\Plugins\SpineBushing Source Code2\NewSpineBushing\RegisterTypes_osimPlugin.cpp(33): error C2371: 'instantiator' : redefinition; different basic types
2>          C:\OpenSim 3.3\sdk\include\OpenSim/OpenSim.h(44) : see declaration of 'instantiator'
2>  SpineBushingTest.cpp
2>  Generating Code...
3>------ Build started: Project: ALL_BUILD, Configuration: Release x64 ------
3>  Building Custom Rule C:/OpenSim 3.3/sdk/APIExamples/Plugins/SpineBushing Source Code2/NewSpineBushing/CMakeLists.txt
3>  CMake does not need to re-run because C:/OpenSim 3.3/sdk/APIExamples/Plugins/SpineBushing Source Code2/NewSpineBushing/Binaries15/CMakeFiles/generate.stamp is up-to-date.
========== Build: 2 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This seems to come from the RegisterTypes_osim.Plugin.cpp file below:

Code: Select all

#include <string>
#include <iostream>
#include <OpenSim/Common/Object.h>
#include "RegisterTypes_osimPlugin.h"

#include "SpineBushingTest.h"

using namespace OpenSim;
using namespace std;

static dllObjectInstantiator instantiator; 
     
//_____________________________________________________________________________
/**
 * The purpose of this routine is to register all class types exported by
 * the Plugin library.
 */
OSIMPLUGIN_API void RegisterTypes_osimPlugin()
{
	Object::RegisterType( SpineBushingTest() );
}

dllObjectInstantiator::dllObjectInstantiator() 
{ 
        registerDllClasses(); 
} 
    
void dllObjectInstantiator::registerDllClasses() 
{ 
        RegisterTypes_osimPlugin(); 
} 
This file I got from the BodyDragForce example, which compiles fine. The only changes I made were replacing two instances of "BodyDragFoce with SpineBushingTest (name of my plug-in). Any ideas what is wrong?

Re: Error Building a Plug-In in Visual Studio

Posted: Thu Oct 26, 2017 5:58 pm
by chrisdembia
I would make sure the plug-in compiles fine before you change anything, even any names.

You might be able to solve your issue by changing the name of the variable in this line:

Code: Select all

static dllObjectInstantiator instantiator;
For example:

Code: Select all

static dllObjectInstantiator myPluginInstantiator;

Re: Error Building a Plug-In in Visual Studio

Posted: Fri Oct 27, 2017 12:11 pm
by pittpanther13
Thank you very much. That seemed to have solved the problem. Was this just a matter of specifying a name in front of "instantiator"? I'm just trying to learn the reasoning behind it.

Ryan

Re: Error Building a Plug-In in Visual Studio

Posted: Fri Oct 27, 2017 1:24 pm
by tkuchida
The error message included the text "error C2371: 'instantiator' : redefinition" which indicates that the variable name had already been defined (used elsewhere). The error message points to line 44 in OpenSim.h (which appears on line 45 in 4.0): https://github.com/opensim-org/opensim- ... nSim.h#L45.