Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

This directory contains the following files:

hello_ffi_builder.py # This is the ffi python file that will generate # a shared object that can be imported by python

hello.py # The python file that will import and run # the Hello function

hello.so -> ../_Go/hello.so # The shared object generated by go build hello.h -> ../_Go/hello.h # The C header file generated by go build

The symbolic links are the files that were generated by executing go build -buildmode=c-shared -o hello.so . in the _Go directory.

In order to execute the Hello function from the shared object first run hello_ffi_builder.py to generate the shared object that can be directly imported by python.

$ ./hello_ffi_builder.py 
running build_ext
building 'pyhello' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c pyhello.c -o ./pyhello.o
gcc -pthread -shared -Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ./pyhello.o hello.so -L/usr/lib64 -lpython2.7 -o ./pyhello.so
$ ls pyhello*
pyhello.c  pyhello.o  pyhello.so

Now we have pyhello.so and we can run the hello.py that imports this shared object and executes the Hello() function originally written in Go.

$ LD_LIBRARY_PATH=$(pwd) ./hello.py                                                                                                                                         
Hello! The square root of 4 is: 2