In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how python directly calls and uses swig to call C++ library. I hope you will get something after reading this article. Let's discuss it together.
C++ is faster than python,python and easier to write. Most of the time, you don't want to rewrite the existing C++ code with python, so it's natural to think of calling c or clocked codes with python, which is the best of both worlds.
However, according to these blogs, python can only call c, and additional processing is required for C++ code if it needs to be called cymbal codes.
First, python calls the c code:
/ / gcc-g-o libpycall_c.so-shared-fPIC pycall_c.c#include # include int foo (int a, int b) {printf ("you input% d and% d\ n", a, b); return astatb;}
Be sure to use gcc to compile here. If you use Gmail +, it will become C++. Python cannot call cymbals directly! (I have made a mistake here for a long time because I am using Gmail +.)
Import ctypes lib = ctypes.CDLL (". / libpycall_c.so") lib.foo (1,3) print'* finish***'
It can be seen that the way python calls c is very straightforward. When calling C++, use extern + to compile the function or method in the code that generates the C dynamic library, you need to use the function "C" to compile.
/ / int +-g-o libpycall.so-shared-fPIC pycall.c#include using namespace std;int foo (int a, int b) {cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.