Quantcast

c static lib to c#, superLU wrapper bugs for help

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

c static lib to c#, superLU wrapper bugs for help

251017378
Deal all,

While setting up swig(swigwin-3.0.12) to wrapper the c language lib, superlu_5.2.1(http://crd-legacy.lbl.gov/~xiaoye/SuperLU/)to c#, I came across certain issues.
I do as follows:
1. cmake a vs2013 project, ran ok, successfully got a static lib(superlu.lib) by the default setting.
2. swig and built a dll.
   2.1 build a empty dll win32 project, setting it properties in Configuration Properties->linker->inputs->additional dependencies,input the full path of superlu.lib.
   2.2 import the test.i file,set its  properties as "costom build item",then configurate the Command Line as:      
           echo Invoking SWIG...
           echo SWIG_HOME=$(SWIG_HOME)
           echo on
           $(SWIG_HOME)\swig.exe  -csharp -outdir  "$(SolutionDir)$(ProjectName)\interface"  "%(FullPath)"
           echo off
   2.3 set the Outputs : %(Filename)_wrap.cxx ,Ok!
   2.4 build, report one error: slu_scomplex.h(31): error : Syntax error in input(3). the cursor locating on this line of the slu_scomplex.h:  typedef struct { float r, i; } complex;  
         I google and try  a lot about this error, but I failed.  ok, I can compromise for the complex part is not necessarily what I need, then I comment two lines about "slu_scomplex.h" in the test.i file.
   
   2.5 go ahead and rebuild, it seems ok. many c# files were built in the interface directory, and a test_wrap.c was also built.
   2.6 import the test_wrap.c and all the superlu header files into the project,rebuild, then a lot of errors happened.such as:
                error C2016: C requires that a struct or union has at least one member
                error C2059: syntax error : ')'
                .........
 Could you please help me to figure this out. Why swig still failed and show the errors which seems apparently correct and even the  superlu static lib could be successfully built.Also, if someone can guide me a bit, I will
be happy to fix these bugs myself.

Thank you
Lea

 
/*test.i file*/
  %module Test
   %{
#include "supermatrix.h"
#include "superlu_enum_consts.h"
#include "slu_zdefs.h"
#include "slu_util.h"
#include "slu_sdefs.h"
#include "slu_scomplex.h"
#include "slu_ddefs.h"
#include "slu_dcomplex.h"
#include "slu_Cnames.h"
#include "slu_cdefs.h"
#include "html_mainpage.h"
#include "colamd.h"
%}
%include "supermatrix.h"
%include "superlu_enum_consts.h"
%include "slu_zdefs.h"
%include "slu_util.h"
%include "slu_sdefs.h"
%include "slu_scomplex.h"
%include "slu_ddefs.h"
%include "slu_dcomplex.h"
%include "slu_Cnames.h"
%include "slu_cdefs.h"
%include "html_mainpage.h"
%include "colamd.h"

/*end of test.i file*/
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: c static lib to c#, superLU wrapper bugs for help

William S Fulton


On 3 April 2017 at 09:16, 251017378 <[hidden email]> wrote:
Deal all,

While setting up swig(swigwin-3.0.12) to wrapper the c language lib, superlu_5.2.1(http://crd-legacy.lbl.gov/~xiaoye/SuperLU/)to c#, I came across certain issues.
I do as follows:
1. cmake a vs2013 project, ran ok, successfully got a static lib(superlu.lib) by the default setting.
2. swig and built a dll.
   2.1 build a empty dll win32 project, setting it properties in Configuration Properties->linker->inputs->additional dependencies,input the full path of superlu.lib.
   2.2 import the test.i file,set its  properties as "costom build item",then configurate the Command Line as:
           echo Invoking SWIG...
           echo SWIG_HOME=$(SWIG_HOME)
           echo on
           $(SWIG_HOME)\swig.exe  -csharp -outdir  "$(SolutionDir)$(ProjectName)\interface"  "%(FullPath)"
           echo off
   2.3 set the Outputs : %(Filename)_wrap.cxx ,Ok!
   2.4 build, report one error: slu_scomplex.h(31): error : Syntax error in input(3). the cursor locating on this line of the slu_scomplex.h:  typedef struct { float r, i; } complex;
         I google and try  a lot about this error, but I failed.  ok, I can compromise for the complex part is not necessarily what I need, then I comment two lines about "slu_scomplex.h" in the test.i file.

It isn't clear if your input code is C or C++ as you set the output file to %(Filename)_wrap.cxx indicating C++, but test_wrap.c is C. There is a bug in SWIG for C input code as it thinks complex is a keyword. You can work around this by choosing some other name, eg:

  #define complex ComplexStruct
  typedef struct { float r, i; } complex;

 
   2.5 go ahead and rebuild, it seems ok. many c# files were built in the interface directory, and a test_wrap.c was also built.
   2.6 import the test_wrap.c and all the superlu header files into the project,rebuild, then a lot of errors happened.such as:
                error C2016: C requires that a struct or union has at least one member
                error C2059: syntax error : ')'
                .........

You'll need to debug like any other C code. You need to have a reasonably good grasp of C code in order to use SWIG successfully.
 
William


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Loading...