In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.