28.C_Call_Go_sharedlib

command
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 1 Imported by: 0

README

これは何?

Go側で動的共有ライブラリ(soファイル)を作成して、C言語側からexportされた関数を呼び出すサンプルです。

Goでsoファイルを作成するには、 go build 時に -buildmode=c-shared オプションを付与します。

-buildmode=c-shared を付与してビルドするとsoファイルとヘッダファイルが生成されます。(exportしている関数がある場合)

本サンプルを実行すると以下のようになります。

$ task
task: [build-sofile] go build -o libapp.so -buildmode=c-shared main.go
task: [build-c] gcc -o app app.c -I. -L. -lapp
task: [run] ./app
30

参考情報

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