diff --git a/Software/Development/Language/Go/Basic/Go_Plugin.md b/Software/Development/Language/Go/Basic/Go_Plugin.md index 80f2f1e..3a21d29 100644 --- a/Software/Development/Language/Go/Basic/Go_Plugin.md +++ b/Software/Development/Language/Go/Basic/Go_Plugin.md @@ -24,13 +24,15 @@ func PrintTest(strInput string) { 编译 Go 动态库命令: ```bash -go build -buildmode=plugin +go build -trimpath -buildmode=plugin -ldflags="-w -s" ``` -指定文件编译 Go 动态库命令 +其中 -trimpath 用于从二进制文件中删除文件系统路径信息。 + +指定文件编译 Go 动态库命令: ```bash -go build -buildmode=plugin -o print.so print.go +go build -trimpath -buildmode=plugin -ldflags="-w -s" -o print.so print.go ``` go 动态库方法的使用(main.go): @@ -61,6 +63,12 @@ func main() { } ``` +编译: + +```bash +go build -trimpath -ldflags="-w -s" +``` + Go 1.8 中 plugin 包只提供 Open 和 Lookup 方法,对应打开动态库和获取动态库中的方法。注意获取到的动态动态库方法其实是一个 interface{} 类型,需要将其进行转换后才可以使用。 ## 3.注意