mercredi 1 mars 2017

swig: __cplusplus not being set with -c++?

I am attempting to create a wrapper with swig for a static library (*.a) to consume with Golang.

I am using a mylib.swigcxx file that triggers Golang to call swig with the following options:

swig -go -cgo -intgosize 64 -module mylib \
-o $WORK/mylib/_obj/mylib_wrap.cxx \
-outdir $WORK/mylib/_obj/ \
-I/mylib/lib \
-c++ mylib.swigcxx

The mylib.swigcxx looks like:

%module mylib
%{
    // (snip)
    #include "basic/internal/config.h"
    #include "basic/internal/config_autogen.h"
    // (snip)
%}

%include <typemaps.i>
%include "std_string.i"
%include "std_vector.i"

// This will create 2 wrapped types in Go called
// "StringVector" and "ByteVector" for their respective
// types.
namespace std {
   %template(StringVector) vector<string>;
   %template(ByteVector) vector<char>;
}

// ...
%include "basic/internal/config.h"
%include "basic/internal/config_autogen.h"
// ...

The large library I am attempting to wrap has a header file with the following code:

   70 // C++11 standard
   71 
   72 #if __cplusplus < 201103
   73 
   74 #if defined(_MSC_VER)
   75 #if _MSC_VER < 1700
   76 #error "Compiling OGDF requires Visual C++ 11 (Visual Studio 2012) or higher!"
   77 #endif
   78 
   79 #elif defined(__GNUC__)
   80 #ifndef __GXX_EXPERIMENTAL_CXX0X__
   81 #error "No C++11 support activated for g++ (compile with -std=c++0x or -std=c++11)!"
   82 #endif
   83 
   84 #else
   85 #error "Compiling OGDF requires a C++11 compliant compiler!"
   86 #endif
   87 
   88 #endif
   89 

As you can see, it is checking if __cplusplus is set correctly and if not to display an error.

The errors I get during swig execution is:

/mylib/lib -c++ mylib.swigcxx
/mylib/lib/basic/internal/config.h:85: Error: CPP #error ""Compiling OGDF requires a C++11 compliant compiler!"". Use the -cpperraswarn option to continue swig processing.
/mylib/lib/basic/internal/config.h:254: Error: CPP #error ""OGDF is compiled without LP solver. Check your build configuration."". Use the -cpperraswarn option to continue swig processing.
/mylib/lib/basic/internal/config.h:299: Error: CPP #error ""OGDF is compiled without memory manager. Check your build configuration."". Use the -cpperraswarn option to continue swig processing.

As you can see, it's failing on line 85 for __cplusplus < 201103 and the else clause.

According to the SWIG 3.0 docs, this should be set with the -c++ flag:

__cplusplus                     Defined when -c++ option used

Any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire