go開(kāi)發(fā)中引用靜態(tài)庫(kù).a文件的方法
前言
我使用goland開(kāi)發(fā),下面都是用goland做演示
一、生成demo.a
新建一個(gè)項(xiàng)目,目錄如下

demo.go
package demo
import (
"fmt"
)
func Demo() {
fmt.Printf("hello world")
}
main.go
package main
import "demo"
func main() {
demo.Demo()
}
配置Run/Debug Configurations,在Go tool arguments:后輸入-i,然后運(yùn)行后就會(huì)生成demo.a


二、修改demo.go
在文件頭添加//go:binary-only-package,添加這個(gè)之后就不會(huì)編譯了,這個(gè)在go/build/doc.go文件中最下方有說(shuō)明
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.
運(yùn)行后發(fā)現(xiàn)可以正常調(diào)用到demo.a里面的Demo函數(shù)

提示:必須導(dǎo)入demo里用到的包,要不然會(huì)報(bào)錯(cuò)
到此這篇關(guān)于go開(kāi)發(fā)中引用靜態(tài)庫(kù).a文件的方法的文章就介紹到這了,更多相關(guān)go引用靜態(tài)庫(kù).a文件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Golang中數(shù)據(jù)結(jié)構(gòu)Queue的實(shí)現(xiàn)方法詳解
這篇文章主要給大家介紹了關(guān)于Golang中數(shù)據(jù)結(jié)構(gòu)Queue的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-09-09
Go調(diào)度器學(xué)習(xí)之goroutine調(diào)度詳解
這篇文章主要為大家詳細(xì)介紹了Go調(diào)度器中g(shù)oroutine調(diào)度的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-03-03
go代碼實(shí)現(xiàn)買房貸款月供計(jì)算的方法

