{"id":13714193,"url":"https://github.com/h12w/cwrap","last_synced_at":"2026-01-26T01:14:26.964Z","repository":{"id":12884855,"uuid":"15561422","full_name":"h12w/cwrap","owner":"h12w","description":"Wraps C libraries in Go.","archived":false,"fork":false,"pushed_at":"2023-05-18T20:42:04.000Z","size":134,"stargazers_count":120,"open_issues_count":0,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2026-01-14T01:08:10.354Z","etag":null,"topics":["cgo","go","golang","golang-package"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/h12w.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2014-01-01T06:54:29.000Z","updated_at":"2025-12-30T23:12:20.000Z","dependencies_parsed_at":"2023-07-14T01:17:04.348Z","dependency_job_id":null,"html_url":"https://github.com/h12w/cwrap","commit_stats":null,"previous_names":["hailiang/cwrap"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/h12w/cwrap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h12w%2Fcwrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h12w%2Fcwrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h12w%2Fcwrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h12w%2Fcwrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/h12w","download_url":"https://codeload.github.com/h12w/cwrap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h12w%2Fcwrap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28763299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T00:37:26.264Z","status":"ssl_error","status_checked_at":"2026-01-26T00:37:25.959Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","go","golang","golang-package"],"created_at":"2024-08-02T23:01:54.441Z","updated_at":"2026-01-26T01:14:26.948Z","avatar_url":"https://github.com/h12w.png","language":"Go","funding_links":[],"categories":["Repositories"],"sub_categories":[],"readme":"Cwrap: Wraps C libraries in Go\n==============================\n\nCwrap is a Go wrapper generator for C libraries.\n\nFeatures\n--------\n* No Cgo types exposed out of the wrapper package, and uses as less allocation/copy as possible.\n* C name prefix mapped to Go packages, and a wrapper package can import another wrapper package.\n* Follows Go naming conventions.\n* C union.\n* Use Go language features when possible:\n  * string and bool.\n  * Multiple return values.\n  * Slice, slice of slice and slice of string.\n  * struct with methods. \n  * Go closures as callbacks.\n* Stay out of the way when you need to do it manually for specified declarations.\n\nUsage\n-----\nCwrap itself is a Go package rather than an executable program. Just fill a cwrap.Package struct literal and call it's Wrap method to generate your wrapper package under $GOPATH. Here is a simple example:\n\nSay you want to generate a wrapper package for SDL2, and its header is at\n\n    /usr/local/include/SDL2/SDL2.h\n\nSo the cwrap.Package literal looks like:\n\n    var sdl = \u0026Package{\n\t\tPacName: \"sdl\",\n\t\tPacPath: \"go-sdl\",\n\t\tFrom: Header{\n\t\t\tDir:           \"/usr/local/include/\",\n\t\t\tFile:          \"SDL2/SDL.h\",\n\t\t\tOtherCode:     \"#define _SDL_main_h\",\n\t\t\tNamePattern:   `\\ASDL(.*)`,\n\t\t\tExcluded:      []string{},\n\t\t\tCgoDirectives: []string{\"pkg-config: sdl2\"},\n\t\t\tBoolTypes:     []string{\"SDL_bool\"},\n\t\t},\n\t\tIncluded: []*Package{},\n\t}\n\nThen just call\n\n    err := sdl.Wrap()\n\nExamples\n--------\nIn the examples directory, there are C libraries that I have successfully applied Cwrap, including:\n* Cairo\n* GSL (GNU Scientific Library)\n* MuPDF\n* PLplot\n* SDL2 (Simple DirectMedia Layer)\n\nYou are very welcome to submit examples you think useful to others.\n\nApplications\n------------\n* gr: A minimal PDF viewer based on SDL2 and MuPDF (https://h12.io/gr)\n\nIssue Report\n------------\nCwrap may not cover every possible case and fails to come up with a corrresonding Go type or convertion, then the generated code may not be able to compile. When this happens, do the following steps:\n\n1. Comment out the failed function wrappers till it compiles.\n2. Add the C names of these failed functions to the excluded list (Package.From.Excluded).\n3. Submit the generator example to me. I cannot guarantee anything but I will try to fix critical issues.\n\nTODO\n----\n* Go idiomatic error handling (return error for each function/method).\n* Godoc documentation.\n* Alignment and padding of generated Go struct fields may need more careful checking (It just works fine for now, and I won't spend time on this until a real bug is found).\n\nLimitations\n-----------\n* C variadic functions (...) are not supported.\n\nAcknowledgement\n---------------\nCwrap uses gccxml (http://gccxml.github.io) to parse C headers to an XML file. Thanks very much for their excellent work.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh12w%2Fcwrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh12w%2Fcwrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh12w%2Fcwrap/lists"}