c++ unordered_map of unordered_map to perl
"Duce, Richard via Swig-user" <[email protected]> Thu, 15 Sep 2022 16:35:42 +0000
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <DM6PR12MB26043DABAA4EC1F8EE4108FA83499@DM6PR12MB2604.namprd12.prod.outlook.com> |
[AMD Official Use Only - General]
Hi.
I am new user to swig.
My example is from c++ to perl.
I have managed to get a std:vector of std::string returned from c++ to perl ,
and next up I am attempting to get a std::unordered_map of unordered_map of unordered_map of std::strings returned.
On searching for various answers to questions about this I learnt that support for unordered_map has been added 'recently'
(wsfulton on Aug 31, 2018 said. swig-3.0.12 does not have support for std::unordered_map, but swig-4.0.0 will. )
I was previously using swig 2.0.10
and so have just downloaded and installed 4.0.2 which I am now attempting to use.
My first issue was that although I could see the std_unordered_map.i file in share/swig/4.0.2/std
I kept getting messages about the file not being found.
Finally I discovered the -I argument to include in the command line.
Which I then used as
swig =c++ =perl -I/path/to/swigInstall/share/swig/4.0.2/std myFile.i
myFile.i contains
%module myFile
%{
#include "myFile.h"
#include <unordered_map>
%}
using namespace std;
%include <std_string.i>
%include <std_vector.i>
%include <std_unordered_map.i>
And I had created some templates like...
namespace std {
%template(StdStrVector) vector<std::string>;
%template(StdStrUnOrdMap) unordered_map<std::string,std::string>;
%template(StdStrUnOrdMapL2) unordered_map<std::string,StdStrUnOrdMap>;
%template(StdStrUnOrdMapL3) unordered_map<std::string,StdStrUnOrdMapL2>;
}
Now I managed to get the .i to create the wrap.cxx file and .pm file (In other words, swig now runs to completion.. )
But in attempting to compile the wrap cxx file I get many issues with
usr/bin/g++ -fpic -std=c++11 -O2 -g -Wall -c -I/tools/iccad/.packages/x86_64/RHEL7.2/perl/5.20.2-20210630/lib/5.20.2/x86_64-linux-thread-multi-ld/CORE mfile_wrap.cxx -o myfile_wrap.o
GVConnectivity_cc_wrap.cxx:1721:25: error: 'traits' is not a class template
template <> struct traits< char > {
^
GVConnectivity_cc_wrap.cxx:1721:40: error: explicit specialization of non-template 'swig::traits'
template <> struct traits< char > {
^
GVConnectivity_cc_wrap.cxx:1722:15: error: 'pointer_category' does not name a type
typedef pointer_category category;
^
GVConnectivity_cc_wrap.cxx:2148:25: error: 'traits' is not a class template
template <> struct traits< Verific::Net > {
^
GVConnectivity_cc_wrap.cxx:2148:46: error: 'swig::traits' is not a template type
template <> struct traits< Verific::Net > {
^
GVConnectivity_cc_wrap.cxx:2156:22: error: 'traits' is not a class template
template <> struct traits<std::vector< Verific::Net*, std::allocator< Verific::Net * > > > {
etc...
in searching through the .i files in share/swig/4.0.2/std I seem to need std_common.i as well..
but that doesn't seem to help
In fact, the swig run gives a bunch of warnings about traits... so its probably not surprising I get compile issues with it
/tools/iccad/.packages/x86_64/RHEL6.8/swig/4.0.2/bin/swig -c++ -perl -I/tools/iccad/.packages/x86_64/RHEL6.8/swig/4.0.2/share/swig/4.0.2/std myfile.i
/tools/iccad/.packages/x86_64/RHEL6.8/swig/4.0.2/share/swig/4.0.2/std/std_basic_string.i:45: Warning 490: Fragment 'StdTraits' not found.
/tools/iccad/.packages/x86_64/RHEL6.8/swig/4.0.2/share/swig/4.0.2/std/std_vector.i:135: Warning 490: Fragment 'StdTraits' not found.
/tools/iccad/.packages/x86_64/RHEL6.8/swig/4.0.2/share/swig/4.0.2/std/std_vector.i:135: Warning 490: Fragment 'StdVectorTraits' not found.
/tools/iccad/.packages/x86_64/RHEL6.8/swig/4.0.2/share/swig/4.0.2/std/std_vector.i:94: Warning 490: Fragment 'StdTraits' not found.
/tools/iccad/.packages/x86_64/RHEL6.8/swig/4.0.2/share/swig/4.0.2/std/std_vector.i:94: Warning 490: Fragment 'StdVectorTraits' not found.
/tools/iccad/.packages/x86_64/RHEL6.8/swig/4.0.2/share/swig/4.0.2/std/std_unordered_map.i:119: Warning 490: Fragment 'StdPairTraits' not found.
/tools/iccad/.packages/x86_64/RHEL6.8/swig/4.0.2/share/swig/4.0.2/std/std_unordered_map.i:119: Warning 490: Fragment 'StdUnorderedMapTraits' not found.
Finally on a whim I found the share/swig/4.0.2/typemaps/ fragments.swg and implicit.swg that seemed to have fragment stuff in..
of course, that didn't help either
so any help would be appreciated in getting my wrap file to compile.
Thanks in advance
Richard Duce
_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user