{"id":16744008,"url":"https://github.com/goccy/cgo-math","last_synced_at":"2025-06-17T07:39:56.781Z","repository":{"id":61627979,"uuid":"246496796","full_name":"goccy/cgo-math","owner":"goccy","description":"Generate libm bridge for resolving undefined symbol in cgo","archived":false,"fork":false,"pushed_at":"2020-03-11T09:11:49.000Z","size":8,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-22T14:08:15.668Z","etag":null,"topics":["cgo","cgo-bindings","go","golang","math"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goccy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-11T06:53:08.000Z","updated_at":"2024-11-29T05:54:27.000Z","dependencies_parsed_at":"2022-10-18T17:45:14.650Z","dependency_job_id":null,"html_url":"https://github.com/goccy/cgo-math","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goccy%2Fcgo-math","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goccy%2Fcgo-math/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goccy%2Fcgo-math/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goccy%2Fcgo-math/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goccy","download_url":"https://codeload.github.com/goccy/cgo-math/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243809884,"owners_count":20351407,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cgo","cgo-bindings","go","golang","math"],"created_at":"2024-10-13T01:42:13.785Z","updated_at":"2025-03-16T01:12:48.659Z","avatar_url":"https://github.com/goccy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cgo-math\nGenerate libm bridge for resolving undefined symbol in cgo\n\n# Example\n\n( Put same example in `_example` directory )\n\n### Working Tree\n\n```\n$ tree\n.\n├── ccall\n│   ├── ccall.c\n│   └── ccall.go\n├── go.mod\n├── go.sum\n└── main.go\n```\n\n### Contents\n\n- `go.mod`\n\n```\nmodule example\n\ngo 1.12\n```\n\n- `main.go`\n\nOnly call `ccall.Sqrt(float64)float64` .\n\n```go\npackage main\n\nimport (\n\t\"example/ccall\"\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(ccall.Sqrt(4))\n}\n```\n\n- `ccall/ccall.go`\n\ndefine `Sqrt(float64)float64` and call C API ( `double callSqrt(double x)` )\n\n```go\npackage ccall\n\n// extern double callSqrt(double x);\nimport \"C\"\n\nfunc Sqrt(x float64) float64 {\n\treturn float64(C.callSqrt(C.double(x)))\n}\n```\n\n- `ccall/ccall.c`\n\ndefine `double callSqrt(double)` and call `sqrt`\n\n```c\n#include \"_cgo_export.h\"\n\ndouble callSqrt(double x) {\n  return sqrt(x);\n}\n```\n\n### Run example\n\n```bash\n$ go run main.go\n# example/ccall\nccall.c:4:10: warning: implicitly declaring library function 'sqrt' with type 'double (double)' [-Wimplicit-function-declaration]\nccall.c:4:10: note: include the header \u003cmath.h\u003e or explicitly provide a declaration for 'sqrt'\n2\n```\n\nProduce **warning: implicitly declaring** because this example doesn't link `libm` .\n\n### Executes cgo-math-bindgen\n\n#### Install CLI\n\n```bash\ngo get github.com/goccy/cgo-math/cmd/cgo-math-bindgen\n```\n\n#### Run generator\n\n```bash\n$ cgo-math-bindgen --package ccall --output ccall\n```\n\nGenerate bridge source to `ccall/bridge_math.go` as `ccall` package\n\n### Try to run example again\n\n```bash\n$ go run main.go\n2\n```\n\nYeah ! we resolved reference to `sqrt` symbol !\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoccy%2Fcgo-math","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoccy%2Fcgo-math","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoccy%2Fcgo-math/lists"}