c_shared

command
v0.5.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2024 License: MIT Imports: 2 Imported by: 0

README

Go側からsoファイルを作成してPythonとCで利用

go build 時に -buildmode=c-shared を付与することで so ファイルと ヘッダファイル が生成される。

$ task run
task: [build] go build -buildmode=c-shared -o libgoadd.so main.go
task: [show] ls -lh libgoadd.so
-rw-r--r-- 1 gitpod gitpod 2.0M Nov 14 07:21 libgoadd.so
task: [show] file libgoadd.so
libgoadd.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=7c44e5b5941164345845b1bb8d3103399b4870d8, with debug_info, not stripped
task: [show] ldd libgoadd.so
        linux-vdso.so.1 (0x00007ffd2b9d6000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd4f6bf7000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fd4f6fa9000)
task: [show] nm -D libgoadd.so | grep 'T Add'
00000000000a1e00 T Add
task: [use] python3 use.py
[FROM GOLANG] library loaded!
[FROM PYTHON] 333
task: [use] gcc -o use-c use.c -L . -l goadd
task: [use] LD_LIBRARY_PATH=. ./use-c
[FROM GOLANG] library loaded!
[FROM C] 333

参考情報

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL