Open
Description
Hi,
I have a SWIG project with two modules, let's call them A
and B
, which generate bindings for C# in two namespaces.
B
depends on A
and imports it like:
%import "A.i"
However, both modules define the same template instantiation:
%template(StringList) std::vector<std::string>;
In SWIG 4.3, this leads to the following warning:
warning 404: Duplicate template instantiation of 'vector< std::string >' with name 'StringList' ignored,
Removing the "duplicate" template from module B
, does not work. The generated C# code will try to use B.StringList
, but StringList
is now only defined in module A
.
Would it be possible to improve the duplicate detection to allow the same template instantiation to co-exist in different modules?
I think it is possible to work around this by adding some typemaps to let module B
use the C# types from the other namespace, but that does not feel right.
Metadata
Metadata
Assignees
Labels
No labels
Activity
Loffe commentedon Jan 10, 2025
Attaching project to reproduce:
swig-issue-3101-duplicate-template.zip
Perhaps the issue is more related to the use of namespaces? The generated C# code of module B does not know the namespace of module A, and just assumes that
StringList
is available in the same namespace.wsfulton commentedon Jan 31, 2025
%import
and C#'s -namespace is not something that is supported and would require a way to set the C# namespace for an imported module. Something similar to setting the module name for an imported header file such as the following in the docs https://swig.org/Doc4.3/Modules.html#Modules_nn1:Probably not too hard to code up in csharp.cxx.
Yes, using typemaps such as 'cstype' should provide a workaround.