Skip to content

Duplicate template instantiation of 'vector< std::string >' with name 'StringList' ignored, #3101

Open
@Loffe

Description

@Loffe

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.

Activity

Loffe

Loffe commented on Jan 10, 2025

@Loffe
Author

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

wsfulton commented on Jan 31, 2025

@wsfulton
Member

%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:

%import(module="base_module") "base.h"

Probably not too hard to code up in csharp.cxx.

Yes, using typemaps such as 'cstype' should provide a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Duplicate template instantiation of 'vector< std::string >' with name 'StringList' ignored, · Issue #3101 · swig/swig