python program calls the C / C ++ Code

This is used to record the problems encountered when generating CAN data frames in some simulation tools Canoe,

Generating CAN data frames, divided into two main concerns:

1. How the start bit signal can be obtained from the name ID length can signal and a signal, and the signal value in accordance with a certain rule have filled in.

2. Because the rules FCAN amount checksum checksum activecount, which is part of the algorithm using C / C ++ best, so python program designed to call the C / C ++ Code (ie this article)

 

1. How python to call C ++ code is:

This is the python official repository cytpes presentation module, you can look at " Fundamental the Data types "

(https://docs.python.org/3/library/ctypes.html)

This provides a simple example of calling C language code

(https://blog.csdn.net/theonegis/article/details/82490549)

The python call C ++ call pointer and an array of pointers ( variables more chaos, better looking about to see it )

(https://blog.csdn.net/weixin_41770169/article/details/90675653)

The python call C code passed in an array to a function, because the pass in essence is a pointer, as the contents of the array parameters will change, two examples

(https://blog.csdn.net/u012449363/article/details/76690540/)

(https://blog.csdn.net/cahesi/article/details/80256638)

 

2. Compile C / C ++ generated dynamic library

How this is to create a C ++ Dynamic Library Project

(https://blog.csdn.net/qianchenglenger/article/details/21599235)

How this is to generate C ++ Dynamic Library

32bit : directly with your C ++ compiler 32 -bit to

64bit : using mingw-w64 compiler (if not see section 3)

Whether 32bit or 64bit, a dynamic library as follows:

cd to your dynamic library project which compiled using the following command

gcc -shared -o yourDynamicLibNmae.dll yourSourceFileName.cpp

The last generation of " yourDynamicLibNmae.dll " file is also desired

 

3. Python and C compilers to be consistent, or are 64bit , or else are 32bit of

 

This is a windows installation mingw-w64 offline installation package , the installation is complete, restart your computer

 

(https://www.cnblogs.com/TAMING/p/9945389.html)

 

4. For the convenience of users, each installed unnecessary python environment, can be packaged into exe

(https://blog.csdn.net/shangxiaqiusuo1/article/details/81113900)

1>  Installation packed library

pip install pyinstaller

2>  In python opening path of the program corresponding to the command line

pyinstaller -F yourEnterFile.py

Corresponding to the generated exe in the same path dist folder inside the name of yourEnterFile.exe

 

This phenomenon that is packaged success

3>  This procedure because it involves dll , so the corresponding dll also copy exe the directory

Double-click yourEnterFile.exe

 

 

 

 

Guess you like

Origin www.cnblogs.com/y-c-y/p/11530708.html