Calling Shared Library functions from Go and Python

  .so, boost-python, c++, go, python

Similar questions here
How can I call linux shared library functions in Go?

but too a beginner to understand it.

I am a C programmer and learning Go in a hard way.
Currently studying and porting an existing Python codes ( and to Go

The existing Python files(along with delphi.cpp) have been compiled and generated .so file
I need to access the functions under delphi.cpp (a C++ with boost python) from Go. calls the class Net defined under delphi.cpp

class NetworkData(object):
    def _init(cls):
    def Func1(cls, keys): 

self.uname = hdd
self.__delphi = delphi.Net(hdd, python3.getAllData, NetworkData, kwargs)

 def TCP(self):
        return self.__delphi.TCP

class getAllData(object):

    def _init(cls):
    ids = {
    "M1":          0x000002,
    "M2":        0x50001,


#include <boost/python/module.hpp>
#include <stdio.h>
#define __PYTHON3__
using namespace boost::python;
using std::string;

    to_python_converter<beint32_t, beint32_to_python>();
    to_python_converter<beint64_t, beint64_to_python>();
    docstring_options doc_options;
    class_<Net>("Net", netDocs, init<string, object, object, dict>())
            .add_property("TCP",                &Net::getTCP,               tcpDocs)


static const char * netDocs =
        Net::Net(string hd, object getDataFn, object _networkdata, dict kwargs)

static const char * tcpDocs =
        std::string Net::getTCP() {
    return <data>();

I copied the .so under these locations.

Program structure


delphi.cpp (uses Boost.Python). I need to import functions(eg TCP) defined under delphi.cpp

Before doing it in Go, I wanted to test the Python function from command prompt.
The subfunctions under delphi.Net are TCP, getType, callT(, UDS .

>>import delphi


I try calling delphi.Net().TCP and the error I got was

Boost.Python.ArgumentError: Python argument types in
Net.init(Net) did not match C++ signature:
init(_object*, std::__cxx11::basic_string<char, std::char_traits, std::allocator >,
boost::python::api::object, boost::python::api::object,

I know I have called the TCP function without passing parameters and I don’t understand how to send the parameters to delphi.Net

delphi.Net(hdd, python3.getAllData, NetworkData, kwargs)

I tried my best to put forth the issue in an understandable way.

How to debug and understand such error?

I will be calling the same in Go using

exec.Command("python", "-c", "import delphi; delphi.Net().TCP)")

I wanted to test this portion from Python and then apply in Go.

Source: Windows Questions C++