Search - User list
Full Version: [HDK] - Multiple operators in one DLL?
Root » Technical Discussion » [HDK] - Multiple operators in one DLL?
Anonymous
I wanted to clean up my library of custom operators so I wanted as a test merge two SOP's and output them in one DLL. So I created small test:

Common.h

#pragma once
//#ifndef _COMMON_H_
//#define _COMMON_H_

#include <SOP/SOP_Node.h>
#include <UT/UT_DSOVersion.h>
#include <UT/UT_Interrupt.h>
#include <GU/GU_Detail.h>
#include <PRM/PRM_Include.h>
#include <PRM/PRM_ChoiceList.h>
#include <OP/OP_Operator.h>
#include <OP/OP_OperatorTable.h>
#include <iostream.h>
#include <string>

using std::cout;
using std::endl;

#define SOP_ONE_SMALL_NAME “sop_one”
#define SOP_ONE_BIG_NAME “HDK SOP One”

#define SOP_TWO_SMALL_NAME “sop_two”
#define SOP_TWO_BIG_NAME “HDK SOP Two”

//#endif


One.h

#pragma once
//#ifndef _SOP_ONE_H_
//#define _SOP_ONE_H_

#include “Common.h”

namespace Mantragora
{
namespace SOP
{
class SOP_One : public SOP_Node
{
public:
virtual
~SOP_One()
override;

static PRM_Template ParameterList;

static auto
CreateSOP(OP_Network* network, const char* name, OP_Operator* op)
-> OP_Node*;

protected:
virtual auto
cookMySop(OP_Context &context)
-> OP_ERROR override;

private:
SOP_One(OP_Network* network, const char* name, OP_Operator* op);
};
}
}

//#endif


One.cpp

#include “SOP_One.h”
using namespace Mantragora:OP;

PRM_Template SOP_One:arameterList = { PRM_Template() };

auto
SOP_One::CreateSOP(OP_Network* network, const char* name, OP_Operator* op)
-> OP_Node*
{ return new SOP_One(network, name, op); }

SOP_One:OP_One(OP_Network* network, const char* name, OP_Operator* op)
: SOP_Node(network, name, op) {}

SOP_One::~SOP_One() {}

auto
SOP_One::cookMySop(OP_Context& context)
-> OP_ERROR
{
UT_AutoInterrupt progress(“Performing Operation”);

// to access input we need to lock it
if (lockInputs(context) >= UT_ERROR_ABORT)
return error();
// to modify geometry we need to make copy of it
duplicateSource(0, context);

unlockInputs();
return error();
}


Two.h

It's the same like One.h, just named properly


Two.cpp

It's the same like One.cpp, just named properly


Registration.cpp

#include “SOP/SOP_One.h”
#include “SOP/SOP_Two.h”
using namespace Mantragora:OP;

auto
newSopOperator(OP_OperatorTable* table)
-> void
{
auto sopOne = new OP_Operator(SOP_ONE_SMALL_NAME, SOP_ONE_BIG_NAME,
SOP_One::CreateSOP,
SOP_One:arameterList,
1, 1,
0);

auto sopTwo = new OP_Operator(SOP_TWO_SMALL_NAME, SOP_TWO_BIG_NAME,
SOP_Two::CreateSOP,
SOP_Two:arameterList,
1, 1,
0);

auto success = table->addOperator(sopOne);
success = table->addOperator(sopTwo);
}


When I compile it, I get those errors:

Error 471 error LNK2005: HoudiniCompilerVersion already defined in Registration.obj C:\Users\mantragora\Desktop\Houdini_Template\Houdini_Template\SOP_One.obj MANTRAGORA_Operators

Error 472 error LNK2005: HoudiniDSOVersion already defined in Registration.obj C:\Users\mantragora\Desktop\Houdini_Template\Houdini_Template\SOP_One.obj MANTRAGORA_Operators

Error 473 error LNK2005: HoudiniCompilerVersion already defined in Registration.obj C:\Users\mantragora\Desktop\Houdini_Template\Houdini_Template\SOP_Two.obj MANTRAGORA_Operators

Error 474 error LNK2005: HoudiniDSOVersion already defined in Registration.obj C:\Users\mantragora\Desktop\Houdini_Template\Houdini_Template\SOP_Two.obj MANTRAGORA_Operators

Error 475 error LNK1169: one or more multiply defined symbols found D:\Dropbox\Programs\Houdini\home\dso\H13.0\MANTRAGORA_Operators_Release_13.0.377.dll MANTRAGORA_Operators


So how to merge two operators in one?

BTW: I'm on Windows.
mtucker
The problem is UT/UT_DSOVersion.h being included in multiple .cpp files. That's where HoudiniDSOVersion and HoudiniCompilerVersion are defined. In spite of being a header file, it doesn't just declare those variables, it actually instantiates them in any object file that includes the header while “MAKING_DSO” is defined.

Just remove it from Common.h and instead include it in Registration.cpp. I believe that should fix your link errors.

Mark
Anonymous
Works. Thanks.
Anonymous
Is there a maximum amount of operators that can be put in one DLL? Right now I got 8 diferent extensions (SOP's, SHOP's, GUI, DM), and they compile OK. Now, once I add another one to the pack I'm getting strange errors like this:


1>c1xx : fatal error C1083: Cannot open source file: ‘਀ⴀ䐀伀倀䔀一嘀䐀䈀开䔀一䄀䈀䰀䔀䐀㴀㄀’: No such file or directory

1>c1xx : fatal error C1083: Cannot open source file: ‘∀䐀㨀尀䐀爀漀瀀戀漀砀尀倀爀漀最爀愀洀猀尀䠀漀甀搀椀渀椀尀䠀䐀䬀尀攀砀愀洀瀀氀攀猀’: No such file or directory

1>c1xx : fatal error C1083: Cannot open source file: ‘嬀洀愀渀琀爀愀最漀爀愀崀尀猀漀甀爀挀攀尀䜀唀䤀尀䜀唀䤀开吀攀洀瀀氀愀琀攀尀䜀唀䤀开吀攀洀瀀氀愀琀攀⸀挀瀀瀀∀’: No such file or directory

1>c1xx : fatal error C1083: Cannot open source file: ‘嬀洀愀渀琀爀愀最漀爀愀崀尀猀漀甀爀挀攀尀刀攀最椀猀琀爀愀琀椀漀渀⸀挀瀀瀀∀’: No such file or directory

1>c1xx : fatal error C1083: Cannot open source file: ‘ⴀ’: No such file or directory

1> 嬀洀愀渀琀爀愀最漀爀愀崀尀猀漀甀爀挀攀尀匀伀倀尀匀伀倀开䌀漀洀瀀愀爀攀䄀琀琀爀椀戀甀琀攀尀匀伀倀开䌀漀洀瀀愀爀攀䄀琀琀爀椀戀甀琀攀⸀挀瀀瀀∀

etc.


The 9 extension can be even without any code, just namespace.
Any ideas?

BTW: No, I'm not from China/Japan or any other asian country. I also don't use asian version of VS .
BTW2: Rigt now I got 8 *.cpp/*.h files with extensions plus one *.h and one *.cpp for common includes/parameters and registration. Adding another *.h + *.cpp to this pack and those errors shows up. It's not a path problem since even if I place this additional pair in the same directory like some other already correctly compiling extensions it fails and shows those errors.
Anonymous
Well, I moved all files into one diretory and it compiles o_O.
I will stick with it till I move all the code and make sure it all works, then I will make modifications to paths.
Anonymous
Nope, error came back. After 10 *.h/*.cpp extension files + Common.h/Registration.cpp, if I try to ad any other extension it fails and prints those chinese signs as errors.

I don't have to even register any other extesnion, just adding additional files to the project that are not called when registered gives those errors.

All files are in the same directory so this is not a problem with the path. If I exchange any new extension with any of those 10 already in the project it compiles correctly, adding more than 10 gives errors..

I'm out of ideas.
Anonymous
Instead of VS I used hcustom to compile this project and it also failed with more than 10 extensions, but it gave a little less herogliphic errors:

C:\Users\mantragora>hcustom “C:\Users\mantragora\Desktop\s\Registration.cpp”
Making ‘Registration.o’ and ‘DDropbox/Programs/Houdini/home/houdini13.0/dso\Re
gistration.dll’ from ‘C:\Users\mantragora\Desktop\s\Registration.cpp’
Registration.cpp
Creating library Registration.lib and object Registration.exp
Registration.o : error LNK2019: unresolved external symbol “public: static class
OP_Node * __cdecl Mantragora:OP:OP_Template::CreateSOP(class OP_Network *,c
har const *,class OP_Operator *)” (?CreateSOP@SOP_Template@SOP@Mantragora@@SAPEA
VOP_Node@@PEAVOP_Network@@PEBDPEAVOP_Operator@@@Z) referenced in function newSop
Operator
Registration.o : error LNK2019: unresolved external symbol “public: static class
OP_Node * __cdecl Mantragora:OP:OP_CreatePolygon::CreateSOP(class OP_Networ
k *,char const *,class OP_Operator *)” (?CreateSOP@SOP_CreatePolygon@SOP@Mantrag
ora@@SAPEAVOP_Node@@PEAVOP_Network@@PEBDPEAVOP_Operator@@@Z) referenced in funct
ion newSopOperator
Registration.o : error LNK2019: unresolved external symbol “public: static class
BM_InputSelector * __cdecl Mantragora:elector::MSS_Create_Polygon_Selector::C
reateSelector(class BM_View &,class PI_SelectorTemplate &)” (?CreateSelector@MSS
_Create_Polygon_Selector@Selector@Mantragora@@SAPEAVBM_InputSelector@@AEAVBM_Vie
w@@AEAVPI_SelectorTemplate@@@Z) referenced in function newSelector
Registration.o : error LNK2019: unresolved external symbol “public: static class
OP_Node * __cdecl Mantragora:OP:OP_NormalCurve::CreateSOP(class OP_Network
*,char const *,class OP_Operator *)” (?CreateSOP@SOP_NormalCurve@SOP@Mantragora@
@SAPEAVOP_Node@@PEAVOP_Network@@PEBDPEAVOP_Operator@@@Z) referenced in function
newSopOperator
Registration.o : error LNK2019: unresolved external symbol “public: static class
OP_Node * __cdecl Mantragora:OP:OP_BridgeGeometry::CreateSOP(class OP_Netwo
rk *,char const *,class OP_Operator *)” (?CreateSOP@SOP_BridgeGeometry@SOP@Mantr
agora@@SAPEAVOP_Node@@PEAVOP_Network@@PEBDPEAVOP_Operator@@@Z) referenced in fun
ction newSopOperator
Registration.o : error LNK2019: unresolved external symbol “public: static class
BM_InputSelector * __cdecl Mantragora:elector::MSS_Begin_Selector::CreateSele
ctor(class BM_View &,class PI_SelectorTemplate &)” (?CreateSelector@MSS_Begin_Se
lector@Selector@Mantragora@@SAPEAVBM_InputSelector@@AEAVBM_View@@AEAVPI_Selector
Template@@@Z) referenced in function newSelector
Registration.o : error LNK2019: unresolved external symbol “public: static class
BM_InputSelector * __cdecl Mantragora:elector::MSS_End_Selector::CreateSelect
or(class BM_View &,class PI_SelectorTemplate &)” (?CreateSelector@MSS_End_Select
or@Selector@Mantragora@@SAPEAVBM_InputSelector@@AEAVBM_View@@AEAVPI_SelectorTemp
late@@@Z) referenced in function newSelector
Registration.o : error LNK2019: unresolved external symbol “public: static class
OP_Node * __cdecl Mantragora:OP:OP_CompareAttribute::CreateSOP(class OP_Net
work *,char const *,class OP_Operator *)” (?CreateSOP@SOP_CompareAttribute@SOP@M
antragora@@SAPEAVOP_Node@@PEAVOP_Network@@PEBDPEAVOP_Operator@@@Z) referenced in
function newSopOperator
Registration.o : error LNK2019: unresolved external symbol “public: static class
OP_Node * __cdecl Mantragora:OP:OP_FindLowestAndHighestValue::CreateSOP(cla
ss OP_Network *,char const *,class OP_Operator *)” (?CreateSOP@SOP_FindLowestAnd
HighestValue@SOP@Mantragora@@SAPEAVOP_Node@@PEAVOP_Network@@PEBDPEAVOP_Operator@
@@Z) referenced in function newSopOperator
Registration.o : error LNK2019: unresolved external symbol “public: static class
OP_Node * __cdecl Mantragora:OP:OP_Template::CreatePOP(class OP_Network *,c
har const *,class OP_Operator *)” (?CreatePOP@POP_Template@POP@Mantragora@@SAPEA
VOP_Node@@PEAVOP_Network@@PEBDPEAVOP_Operator@@@Z) referenced in function newPop
Operator
Registration.o : error LNK2019: unresolved external symbol “public: __cdecl Mant
ragora::Viewport:M:M_Template_SceneHook:M_Template_SceneHook(void)” (??0DM
_Template_SceneHook@DM@Viewport@Mantragora@@QEAA@XZ) referenced in function newR
enderHook
Registration.o : error LNK2019: unresolved external symbol “public: __cdecl Mant
ragora::Viewport::GUI::GUI_PrimitiveHook_Template::GUI_PrimitiveHook_Template(vo
id)” (??0GUI_PrimitiveHook_Template@GUI@Viewport@Mantragora@@QEAA@XZ) referenced
in function newRenderHook
Registration.o : error LNK2019: unresolved external symbol “public: __cdecl Mant
ragora::Viewport::GUI::GUI_ColorTopologyHook::GUI_ColorTopologyHook(void)” (??0G
UI_ColorTopologyHook@GUI@Viewport@Mantragora@@QEAA@XZ) referenced in function ne
wRenderHook
Registration.o : error LNK2019: unresolved external symbol “public: static class
PRM_Template * Mantragora:OP:OP_Template:arameterList” (?ParameterList@SO
P_Template@SOP@Mantragora@@2PAVPRM_Template@@A) referenced in function newSopOpe
rator
Registration.o : error LNK2019: unresolved external symbol “public: static class
PRM_Template * Mantragora:OP:OP_CreatePolygon:arameterList” (?ParameterLi
st@SOP_CreatePolygon@SOP@Mantragora@@2PAVPRM_Template@@A) referenced in function
newSopOperator
Registration.o : error LNK2019: unresolved external symbol “public: static class
PRM_Template * Mantragora:OP:OP_NormalCurve:arameterList” (?ParameterList
@SOP_NormalCurve@SOP@Mantragora@@2PAVPRM_Template@@A) referenced in function new
SopOperator
Registration.o : error LNK2019: unresolved external symbol “public: static class
PRM_Template * Mantragora:OP:OP_BridgeGeometry:arameterList” (?ParameterL
ist@SOP_BridgeGeometry@SOP@Mantragora@@2PAVPRM_Template@@A) referenced in functi
on newSopOperator
Registration.o : error LNK2019: unresolved external symbol “public: static class
PRM_Template * Mantragora:OP:OP_CompareAttribute:arameterList” (?Paramete
rList@SOP_CompareAttribute@SOP@Mantragora@@2PAVPRM_Template@@A) referenced in fu
nction newSopOperator
Registration.o : error LNK2019: unresolved external symbol “public: static class
PRM_Template * Mantragora:OP:OP_FindLowestAndHighestValue:arameterList” (
?ParameterList@SOP_FindLowestAndHighestValue@SOP@Mantragora@@2PAVPRM_Template@@A
) referenced in function newSopOperator
Registration.o : error LNK2019: unresolved external symbol “public: static class
PRM_Template * Mantragora:OP:OP_Template:arameterList” (?ParameterList@PO
P_Template@POP@Mantragora@@2PAVPRM_Template@@A) referenced in function newPopOpe
rator
DDropbox/Programs/Houdini/home/houdini13.0/dso/Registration.dll : fatal error
LNK1120: 20 unresolved externals


Additionally, with 10 extensions VS compiles this project correctly while hcustom fails. Any ideas what else I should look for?
Anonymous
I think that Hcustom doesn't know about other *.cpp files and that's why it complains.

But that doesn't explain why Visual Studio gimes me those strange errors when I add more than 10 extensions. Anyone?
malexander
In order to compile multiple files into a single project, you need to create a ‘main’ file which includes all the other files, such as:
ops.cpp:
#include “SOP_awesome.cpp”
#include “DM_awesome.cpp”
#include “GU_awesome.cpp”


and compile ops.cpp with hcustom. I don't know much about VS so can't help there.
Anonymous
Hm… So should I leave all those newSopOperator()/newPopOperator() etc. functions in each *.cpp file with operator implementations?

I thought that I should just create one type of each function in separate *.cpp file where I also #include all the header files of operators, then just register all the operators at once in each function:
- all sops in one newSopOperator()
– all DM/GR/GUI hooks in one newRenderHook()
etc.
malexander
Yes, you'll need one to have only one newSopOperator() and newRenderHook() method in the DLL, otherwise you'll get symbol conflicts. The only thing your registration file didn't do was to include the cpp files (it included the headers only).
Anonymous
OK, I will correct it.

Thank you.
Anonymous
Does anyone knows how to detect if the code is compiled from VisualStudio vs hcustom? Does hcustom or VS generate any #define I could use to check it?

I would like to know that because including *.cpp files works for hcustom but gives errors for VisualStudio, because in VS I do have those files included in my solution.

EDIT:
I will solve this differently. For development I will make my #define and will include them only when not DEVELOPMENT. But anyway, if someone knows how to detect do we compile from inside of VS or not, it would be good to know too.
mtucker
You could set up your VS project settings to define any arbitrary symbol which you can use to differentiate between the two situations.

Mark
Anonymous
Is there a chance that you remember which of those thousand settings is the correct one to set ?
mtucker
In the project Properties dialog, under C/C++ -> Preprocessor, the “Preprocessor Definitions” field lets you define any symbols you want. Make sure to set the Configuration menu to in the upper left hand corner of the dialog to “All Configurations” to the symbol is set whether you are compiling for debug or release.

Mark
Anonymous
Thank you!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB