The method of referencing static library. A file in go development

Time:2021-3-6

preface

I use Golan to develop, and the following are all demonstrations with Golan

1、 Generate demo. A

Create a new project with the following contents

在这里插入图片描述

demo.go


package demo

import (
	"fmt"
)

func Demo() {
	fmt.Printf("hello world")
}

main.go


package main

import "demo"

func main() {
	demo.Demo()
}

Configure run / debug configurations, enter – I after go tool arguments: and then generate demo. A after running

在这里插入图片描述
在这里插入图片描述

2、 Modification demo.go

Add / / go: binary only package in the file header. After adding this, it will not be compiled. This is in go / build/ doc.go There are instructions at the bottom of the file

demo.go


//go:binary-only-package

package demo

import (
	_ "fmt"
)

func Demo() {
}

//	//go:binary-only-package
//
//	package mypkg
//
// The source code may include additional Go code. That code is never compiled
// but will be processed by tools like godoc and might be useful as end-user
// documentation.

After running, it is found that you can call the demo function in demo. A normally

在这里插入图片描述

Tip: you must import the package used in demo, otherwise you will report an error

This article about how to refer to the static library. A file in go development is introduced here. For more information about how to refer to the static library. A file in go, please search the previous articles of developer or continue to browse the following related articles. I hope you can support developer more in the future!

Recommended Today

Quickly use the latest 15 common APIs of vue3

Before that, I wrote a blog to introduce the new features of vue3. I had a brief understanding of the features of vue3, and at the end of the article, I gave you a little experience in vue3Compsition APISimple use of Address of last article: follow Youda’s steps and experience the new features of vue3 […]