Reputation: 223
I would like to use Swig to generate C# wrappers for my c++ classes. I am facing the following problem:
I have defined an enum that uses values from a third party (closed source) library. The values are declared inside HEADER_FROM_3RD_PARTY_LIB.h as
#define 3RD_PARTY_LIB_CONST_VALUE_1 -4
#define 3RD_PARTY_LIB_CONST_VALUE_1 -10
My header file looks like:
#include "HEADER_FROM_3RD_PARTY_LIB.h"
namespace Foo
{
namespace Bar
{
class MyClass
{
public:
enum MyEnum
{
Enum1 = 3RD_PARTY_LIB_CONST_VALUE_1,
Enum2 = 3RD_PARTY_LIB_CONST_VALUE_2
};
}
}
}
I am using the following swig code:
%module cpp
%{
#include "MyClass.h"
%}
%include <windows.i>
%include "MyClass.h"
The wrapper is successfully generated but the generated csharp file has the following enum generated:
public enum MyEnum
{
Enum1 = 3RD_PARTY_LIB_CONST_VALUE_1,
Enum2 = 3RD_PARTY_LIB_CONST_VALUE_2
}
Obviously this generates an error since C# cannot find the 3RD_PARTY_LIB_CONST_VALUE_1 and 3RD_PARTY_LIB_CONST_VALUE_2 values.
Any ideas who could this be resolved? I had a look at Swig examples but could not find something similar.
Upvotes: 1
Views: 571
Reputation: 223
The only solution I found so far was either to include
#include "HEADER_FROM_3RD_PARTY_LIB.h"
in the swig file or redefine the values again in the swig file
#define 3RD_PARTY_LIB_CONST_VALUE_1 -4
#define 3RD_PARTY_LIB_CONST_VALUE_1 -10
Any other suggestions how this could be improved? The problem with the first approach is that by including the entire header file I get lots of auto generated files that I do not need.
Upvotes: 1