Debian Codegraph @

examples/libc/main.go

raw symbols SCIP
1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors
3
4 //go:build darwin || freebsd || linux || netbsd || windows
5
6 package main
7
8 import (
9 "fmt"
10 "runtime"
11
12 "github.com/ebitengine/purego"
13 )
14
15 func getSystemLibrary() string {
16 switch runtime.GOOS {
17 case "darwin":
18 return "/usr/lib/libSystem.B.dylib"
19 case "freebsd":
20 return "libc.so.7"
21 case "linux":
22 return "libc.so.6"
23 case "netbsd":
24 return "libc.so"
25 case "windows":
26 return "ucrtbase.dll"
27 default:
28 panic(fmt.Errorf("GOOS=%s is not supported", runtime.GOOS))
29 }
30 }
31
32 func main() {
33 libc, err := openLibrary(getSystemLibrary())
34 if err != nil {
35 panic(err)
36 }
37 var puts func(string)
38 purego.RegisterLibFunc(&puts, libc, "puts")
39 puts("Calling C from Go without Cgo!")
40 }