我有 golang 代码,例如:
import (
"github.com/bobertlo/go-mpg123/mpg123"
)
func main() {
...
}
从终端构建此代码。我必须设置以下环境变量:
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/opt/homebrew/Cellar/mpg123/1.32.3/include
export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/Cellar/mpg123/1.32.3/lib
现在我想使用 vscode 进行构建。我在下面配置launch.json、tasks.json:
// launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"preLaunchTask": "Set CGO_CFLAGS",
"program": "${fileDirname}"
}
]
}
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Set C_INCLUDE_PATH",
"type": "shell",
"command": "export C_INCLUDE_PATH=$C_INCLUDE_PATH:/opt/homebrew/Cellar/mpg123/1.32.3/include",
"problemMatcher": []
},
{
"label": "Set LIBRARY_PATH",
"type": "shell",
"command": "export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/Cellar/mpg123/1.32.3/lib",
},
{
"label": "Set CGO_CFLAGS",
"type": "shell",
"dependsOn":["Set C_INCLUDE_PATH", "Set LIBRARY_PATH"],
"dependsOrder": "sequence",
},
]
}
但是没有成功。据报道:
Build Error: go build -o /Users/xxx/Projects/portauio-go/examples/__debug_bin2329559837 -gcflags all=-N -l .
# github.com/bobertlo/go-mpg123/mpg123
../../../../go/pkg/mod/github.com/bobertlo/[email protected]/mpg123/mpg123.go:8:10: fatal error: 'mpg123.h' file not found
#include <mpg123.h>
^~~~~~~~~~
1 error generated. (exit status 1)
我怎样才能让它发挥作用?