Get the App
SLTechnology News&Howtos  ›  Servers  › 

A detailed explanation of the dynamic Link Library of the method of python calling Candlestick + in ubuntu

Shulou Source: shulou.com Published: 2022-06-02 02:27:25 09月16日 Update

Install boost

There are many ways for python to call CramCure +, and boost.python is used in this article. Considering that there are a lot of development work on boost in the later stage, boost is installed together, and the Boost library is divided into two parts to use, one is to use the corresponding header file directly, and the other is to compile and install the corresponding library before you can use it.

For specific installation methods, please refer to: https://www.jb51.net/article/150380.htm

The use here is:

Sudo apt-get install libboost-all-dev

Server side

Send after serialization

Main.cpp:

# include # include "libUO.h" int main () {UO_C_Socket t UO_C_Socket::StartSocketServer,&t / t.StartSocketServer (", 4121); boost::thread T1 (boost::bind (& UO_C_Socket::StartSocketServer,&t,", 4121)); sleep (2); / / boost::thread T2 (boost::bind (& UO_C_Socket::StartSocketClient,&t, "127.0.0.1", 4121)); / / t2.join (); t1.join (); return 0;}

Client

The client implements basic functions in UO_BaseFun.h, encapsulates it and exports it through boost_python. Pay special attention to the name in BOOST_PYTHON_MODULE and the so file from the last make.

The same name, otherwise there will be an error, the wrong name has been forgotten

UO_libdll_py_wrap.cpp:

# include # include "UO_BaseFun.h" BOOST_PYTHON_MODULE (UO_BaseFun) / / python module {/ / boost::python::class_ ("UO_C_Socket") boost::python::class_ ("UO_C_Socket") .def ("StartSocketClient", & UO_C_Socket::StartSocketClient) / / .def ("getname", & student::getname) / / .def ("setage") & student::setage) / / .def ("getage", & student::getage) / / .add _ property ("name", & student::getname,&student::setname) / / .add _ property ("age", & student::getage,&student::setage) }

Special attention is paid to the difference between compilation and linking in makefile, in which undefined symbol errors need to be added to the dynamic link library-lboost_filesystem and so on. An error that cannot find pyconfig.h should be included

-I/usr/include/python2.7. Generate a UO_BaseFun.so file after make is finished

Makefile:

UO_BaseFun.so:UO_libdll_py_wrap.o L/usr/lib/x86_64-linux-gnu + UO_libdll_py_wrap.o-o UO_BaseFun.so-shared-fPIC-L/usr/lib/x86_64-linux-gnu\-lboost_filesystem-lboost_thread-lboost_serialization-lboost_python-lboost_system UO_STR.o: Gmail +-c UO_STR.h-o UO_STR.o-I/usr/include/boost\ #-lboost_serialization UO_BaseFun.o:UO_STR.o Gmail +-c UO_BaseFun.h-o UO_BaseFun.o-I/usr/include/boost\ #-lboost_system-lboost_filesystem-lboost_thread-lboost_serialization UO_libdll_py_wrap.o:UO_BaseFun.o Gmail +-c UO_libdll_py_wrap.cpp-o UO_libdll_py_wrap.o-fPIC-I/usr/include/python2.7 #-lboost_serialization clean: rm-rf UO_STR.o O_libdll_py_wrap.o UO_BaseFun.o rm-rf UO_BaseFun.so

Verification

UO_StoreSystem_py.py:

Import UO_BaseFuntest = UO_BaseFun.UO_C_Socket () test.StartSocketClient ("127.0.0.1", 4121)

Summary:

The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.

Tags: Error file method content name client client reference learning work compilation dynamic link two value function done that is sequence development work Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Technology Linux Redmi OPPO Reno