Sometimes python needs to refer to some open source libraries of go, and then go needs to be compiled into a callable library for python.
go code
package main//The package must be main import( "C"//Requires support from C library to facilitate type conversion) func main(){} //It's very important, export means mapping Go functions to Python function calls//If there is no export, then the .h file cannot be generated, and python cannot call the function //export HelloWorld func HelloWorld() * { return ("i'm zero wood") }
Very important, export means mapping Go functions to Python function calls
If there is no export, then the .h file cannot be generated, and python cannot call the function
Go compiled into a python call library, the compilation environment is ubuntu18.04.1 LTS
Compile commands
go build -buildmode=c-shared -o
A file will be generated
Then there are functions in python calls
import ctypes lib = ("./") helloWorld = = ctypes.c_char_p print(helloWorld())
This is the article about the problem of python compiling the so library without .h files after compiling. For more related contents of go compiled so library without .h files, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!