{"id":41,"date":"2006-04-27T14:07:39","date_gmt":"2006-04-27T13:07:39","guid":{"rendered":"http:\/\/www.hlynes.com\/2006\/04\/27\/swig-and-c-on-solaris\/"},"modified":"2006-08-08T19:31:10","modified_gmt":"2006-08-08T18:31:10","slug":"swig-and-c-on-solaris","status":"publish","type":"post","link":"http:\/\/www.hlynes.com\/?p=41","title":{"rendered":"SWIG and C++ on Solaris"},"content":{"rendered":"<p>Here at WeSC we have a potentially very useful piece of kit from <a href=\"http:\/\/www.cybula.com\/cortex_II.htm\">Cybula<\/a> which is essentially a set of neural-net based pattern matching algorithms blown into some FPGAs.<\/p>\n<p>Now I have to advise some researchers about how easy it will be to use this kit for a particular project. My ability to advise is limited by the fact that the API for this kit is written in C++. This makes it hard for a mere sysadmin like myself to play with it.<\/p>\n<p>I have been vaguely aware of <a href=\"http:\/\/www.swig.org\">SWIG<\/a> for a while as a mechanism for building language-bindings to C and C++ so I decided to give it a whirl.<\/p>\n<p>I installed swig from sunfreeware. After browsing the <a href=\"http:\/\/www.swig.org\/tutorial.html\">tutorial<\/a> for a while I decided to take the simple approach to building an interface file.<\/p>\n<pre>%module aura\r\n%{\r\n\/* Includes the header in the wrapper code *\/\r\n#include \"aura.h\"\r\n%}\r\n\r\n\/* Parse the header file to generate wrappers *\/\r\n%include \"aura.h\"<\/pre>\n<p>Then I used swig to generate the python and C++ code.<\/p>\n<pre>swig -python -c++ -I\/opt\/Aura\/2.4.2\/include aura.i<\/pre>\n<p>And built the libraries from that<\/p>\n<pre>g++ -shared -I\/usr\/local\/include\/python2.4 -I\/opt\/Aura\/2.4.2\/include -c aura_wrap.cxx<\/pre>\n<p>This left me with aura.py and _aura.so which look like a python module to me.<\/p>\n<pre>Python 2.4 (#1, Dec  1 2004, 05:20:08)\r\n[GCC 3.3.2] on sunos5\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n>>>import aura<\/pre>\n<p>Now I just need to work out how to use it. Assuming this module actually works and isn&#8217;t just an empty shell I may have to try building Java and Perl modules later.<\/p>\n<p><strong>Edited:<\/strong> 16:27 to include some bug-fixes<\/p>\n<p>After playing around with this some more I realized that I had indeed created a completely empty binding. So I went through aura.h and manually included all the header files that it pulled in.<\/p>\n<pre>%module aura\r\n%{\r\n\/* Includes the header in the wrapper code *\/\r\n#include \"aura.h\"\r\n#include \"auraErrorTable.h\"\r\n#include \"auraTypes.h\"\r\n#include \"auraStructures.h\"\r\n#include \"auraException.h\"\r\n#include \"auraSearchEngine.h\"\r\n%}\r\n\r\n\/* Parse the header file to generate wrappers *\/\r\n%include \"aura.h\"\r\n%include \"auraErrorTable.h\"\r\n%include \"auraTypes.h\"\r\n%include \"auraStructures.h\"\r\n%include \"auraException.h\"\r\n%include \"auraSearchEngine.h\"<\/pre>\n<p>This produced much larger python and c++ files so I guessed I was on the right track. I also realized that the g++ command wasn&#8217;t linking in the aura library and that I would have to do it by hand<\/p>\n<pre>g++ -shared -c aura_wrap.cxx -o aura.o -I\/usr\/local\/include\/python2.4 -I\/opt\/Aura\/library\/include\r\n\r\nld -G -o _aura.so aura.o \/opt\/Aura\/library\/lib\/SunOS\/libaura.a<\/pre>\n<p>The path changes were introduced when I realised I was trying to build a 64bit version of libaura into a 32bit version of python.<\/p>\n<pre>Python 2.4 (#1, Dec  1 2004, 05:20:08)\r\n[GCC 3.3.2] on sunos5\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n>>> import aura\r\n>>> dir(aura)\r\n['ERROR_CANNOT_READ_STREAM', 'ERROR_CANNOT_WRITE_STREAM', 'ERROR_COLUMN_INVALID',<\/pre>\n<pre>'ERROR_CONSTRAINTS', 'ERROR_FORMAT_INVALID', 'ERROR_INITIALISED', 'ERROR_MASK_INVALID',<\/pre>\n<pre>'ERROR_MAX_SCORE', 'ERROR_MEMORY', 'ERROR_MISMATCH', 'ERROR_OPTIMISATION_SETTING_INVALID',<\/pre>\n<pre>'ERROR_PARTITION_INVALID', 'ERROR_PATTERN_INVALID', 'ERROR_RANGES_INVALID',<\/pre>\n<pre>'ERROR_RETAINED_ID_INVALID', 'ERROR_ROW_INVALID', 'ERROR_SAME_OBJECT', 'ERROR_SIZES_INVALID',<\/pre>\n<pre>'ERROR_UNIMPLEMENTED', 'ERROR_UNINITIALISED', 'Exception', 'Exception_swigregister', 'NULL', 'OK',<\/pre>\n<pre>'Pattern', 'Pattern_swigregister', 'Preferences', 'Preferences_swigregister',<\/pre>\n<pre>'RetainedInfo', 'RetainedInfo_swigregister', 'SearchCharacteristics', 'SearchCharacteristics_swigregister', 'SearchConstraints',<\/pre>\n<pre>'SearchConstraints_swigregister', 'SearchControl', 'SearchControl_swigregister', 'SearchEngine', 'SearchEngine_swigregister',<\/pre>\n<pre>'SerialiseControl', 'SerialiseControl_swigregister', 'Sizes', 'Sizes_swigregister', 'StorageType', 'StorageType_swigregister',<\/pre>\n<pre>'WARN_COLUMN_IGNORED', 'WARN_NO_BITS_TO_STORE', 'WARN_RETAINED_ID_INVALID',<\/pre>\n<pre>'WARN_ROW_IGNORED', 'WARN_SHRINKAGE_IGNORED', 'WARN_STORE_CHANGED', 'WARN_TRUNCATED',<\/pre>\n<pre>'__builtins__', '__doc__', '__file__', '__name__', '_aura', '_newclass', '_object', '_swig_getattr', '_swig_repr',<\/pre>\n<pre>'_swig_setattr', '_swig_setattr_nondynamic', 'cvar', 'new', 'new_instancemethod']\r\n>>> x = aura.SearchEngine\r\n>>> dir(x)\r\n['ClearRetained', 'Copy', 'GetColumn', 'GetRetainedIds', 'GetRow', 'GetSizes', 'IncreaseSize', 'Initialise',<\/pre>\n<pre>'Merge', 'Optimise', 'Remove', 'Search', 'Serialise', 'Store', '__class__', '__del__', '__delattr__', '__dict__',<\/pre>\n<pre>'__doc__', '__getattr__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__',<\/pre>\n<pre>'__reduce_ex__', '__repr__', '__setattr__', '__str__', '__swig_destroy__', '__swig_getmethods__',<\/pre>\n<pre>'__swig_setmethods__', '__weakref__']<\/pre>\n<p>Result!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here at WeSC we have a potentially very useful piece of kit from Cybula which is essentially a set of neural-net based pattern matching algorithms blown into some FPGAs. Now I have to advise some researchers about how easy it will be to use this kit for a particular project. My ability to advise is &hellip; <a href=\"http:\/\/www.hlynes.com\/?p=41\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">SWIG and C++ on Solaris<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-41","post","type-post","status-publish","format-standard","hentry","category-tech"],"_links":{"self":[{"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/posts\/41"}],"collection":[{"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=41"}],"version-history":[{"count":0,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=\/wp\/v2\/posts\/41\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.hlynes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.hlynes.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}