I would like to be able to use CoolProp c++ library inside my Go code. Unfortunately, there is currently no wrapper for Go (CoolProp Wrappers) so I'm trying to generate it by myself using SWIG.
First I get the source file from coolpop
repository. The main header file is coolprop/include/CoolProp.h
git clone git@github.com:CoolProp/CoolProp.git coolprop
Basically the header file look like :
#ifndef CoolProp_H
#define CoolProp_H
#include <string>
#include <vector>
#include "DataStructures.h"
namespace CoolProp {
double Props1SI(std::string FluidName, std::string Output);
/* many others functions in the real file */
} /* namespace CoolProp */
#endif
Below is the interface file that I write inspired by zacg repository.
gocoolprop.i
%module gocoolprop
%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 "coolprop/include/CoolProp.h"
I'm generating gocoolprop.go and gocoolprop_wrap.cxx using the following command:
swig -go -cgo -c++ -intgosize 64 gocoolprop.i
The swig command works well and the files are generated without any errors. My IDE is even able to recognize all the function when I import the go package.
However, when I try to build the package I obtain a lot of errors all similar to :
# gocoolprop
gocoolprop_wrap.cxx: In function 'double _wrap_Props1SI_gocoolprop_f0fd25a1f15e9efe(_gostring_, _gostring_)':
gocoolprop_wrap.cxx:632:20: error: 'CoolProp' has not been declared
result = (double)CoolProp::Props1SI(arg1,arg2);
The 'CoolProp' is a namespace inside the CoolProp.h header file. I think I may have to add something inside the gocoolprop.i file for this. I take a look inside the c++ part of the swig documentation, but I didn't find anything special about namespaces.
Any advice would be very helpful, it's my first time using swig.
I'm using Go version 1.11 windows/amd64 and SWIG Version 3.0.12 compiled with with i686-w64-mingw32-g++ [i686-w64-mingw32].