no matching function for call to and other errors in wrapper code

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

no matching function for call to and other errors in wrapper code

anterak13
Hi everyone, this is my first post on swig-user.

Running the default swig3.0 as available under ubuntu 16.04LTS with gcc/g++ 5.4.0.

I'm trying to use swift to wrap a C++ SAT solver for java using swig. I have
no control over the c++ code I'm trying to wrap.

I wrote a simple swig configuration file with a few %rename and %ignore and
I've managed to call swig and obtain a cpp file and some java code which
seems to contain every method I need to be wrapped. So far so good.

When trying to compile the generated c++ file using gcc 5.4.0

$ g++ -fPIC sharpCDCL_wrap.cpp -I${JNI_HOME} -I${JNI_HOME}/linux -I../..

(remark: -I../.. is added because it is the root of the solver's source
files
and all includes are relative to this root path, and that the wrapper code
is generated in a directory two subfolders below the root)

I get a few hundreds of errors of different kinds, it seems I'm doing
something wrong but I can't figure out what.

# error kind 1 bad initialization:

sharpCDCL_wrap.cpp: In function ‘jlong
Java_sharpCDCL_sharpCDCLJNI_Solver_1clausesBegin(JNIEnv*, jclass, jlong,
jobject)’:
sharpCDCL_wrap.cpp:2243:18: error: no matching function for call to
‘Minisat::ClauseIterator::ClauseIterator()’
   ClauseIterator result;
                  ^
In file included from ../../minisat/core/Solver.h:16:0,
                 from sharpCDCL_wrap.cpp:234:
../../minisat/core/SolverTypes.h:297:5: note: candidate:
Minisat::ClauseIterator::ClauseIterator(const Minisat::ClauseAllocator&,
const CRef*)
     ClauseIterator(const ClauseAllocator& _ca, const CRef* _crefs) :
ca(_ca), crefs(_crefs){}
     ^
../../minisat/core/SolverTypes.h:297:5: note:   candidate expects 2
arguments, 0 provided
Minisat::ClauseIterator::ClauseIterator()

The swig generated code that triggers this error is the following:

```cpp
SWIGEXPORT jlong JNICALL
Java_sharpCDCL_sharpCDCLJNI_Solver_1clausesBegin(JNIEnv *jenv, jclass jcls,
jlong jarg1, jobject jarg1_) {
  jlong jresult = 0 ;
  Minisat::Solver *arg1 = (Minisat::Solver *) 0 ;
  ClauseIterator result;

  (void)jenv;
  (void)jcls;
  (void)jarg1_;
  arg1 = *(Minisat::Solver **)&jarg1;
  result = ((Minisat::Solver const *)arg1)->clausesBegin();
  *(ClauseIterator **)&jresult = new ClauseIterator((const ClauseIterator
&)result);
  return jresult;
}
```

So the error comes from having the unititialized declaration

```cpp
ClauseIterator result;
```

 Somehow it seems that the uninitialized declaration silently calls
a default constructor that does not exist, since the constructor for a
ClauseIterator takes two arguments and not 0.

# other declaration errors, different flavor:

```
sharpCDCL_wrap.cpp:5070:53: error: expected primary-expression before ‘)’
token
   Minisat::SimpSolver *arg1 = (Minisat::SimpSolver *) 0 ;
```

seems like g++ does not like the casting 0 to a pointer type.
or casting anything really:

```
sharpCDCL_wrap.cpp:5127:61: error: expected primary-expression before ‘)’
token
     *(Minisat::Solver **)&baseptr = *(Minisat::SimpSolver **)&jarg1;
```

# private methods used by the swig-generated code:

```
In file included from ../../minisat/utils/Options.h:30:0,
                 from sharpCDCL_wrap.cpp:233:
../../minisat/mtl/Vec.h: In function ‘void
Java_sharpCDCL_sharpCDCLJNI_Solver_1model_1set(JNIEnv*, jclass, jlong,
jobject, jlong)’:
../../minisat/mtl/Vec.h:48:14: error: ‘Minisat::vec<T>& Minisat::vec<T,
_Size>::operator=(Minisat::vec<T>&) [with T = Minisat::lbool; _Size = int]’
is private
     vec<T>&  operator=(vec<T>& other);
              ^
sharpCDCL_wrap.cpp:2840:8: error: within this context
   arg2 = *argp2;
```

# operator= related errors:

```
 error: non-static reference member ‘const Minisat::ClauseAllocator&
Minisat::ClauseIterator::ca’, can’t use default assignment operator
```

# namespace erros

sharpCDCL_wrap.cpp:5127:39: error: ‘SimpSolver’ is not a member of ‘Minisat’
     *(Minisat::Solver **)&baseptr = *(Minisat::SimpSolver **)&jarg1;

I've double checked and SimpSolver is indeed declared in the
Minisat namespace, and in the swig interface file proper includes have been
added to make sure all
relevant headers are pulled by the wrapper (these are virtually all there is
to know except for some templates that are used internally to the solver.

%{
#include "minisat/utils/System.h"
#include "minisat/utils/ParseUtils.h"
#include "minisat/utils/Options.h"
#include "minisat/core/Solver.h"
#include "minisat/core/SolverTypes.h"
#include "minisat/core/Dimacs.h"
#include "minisat/core/VarFileParser.h"
%}

What am I doing wrong ?
What can I do to fix these issues. ?

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user