You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu环境下VSCode调试Go程序时无法加载plugin(wc.so)的问题解决咨询

Fixing "plugin was built with a different version of package" Error in Go Plugin Debugging

I’ve run into this exact issue multiple times when working with Go plugins—this error almost always boils down to mismatched environments between your plugin compilation and the main program (or debugger setup). Let’s walk through the fixes step by step:

1. Verify You’re Using the Exact Same Go Version

Go plugins are extremely sensitive to version mismatches. First, check the Go version in your terminal (where you compiled the plugin):

go version

Then confirm VS Code is using the same version:

  • Open VS Code settings (Ctrl+,)
  • Search for Go: Go Path and ensure it points to the same Go installation as your terminal.
  • You can also verify via the command palette (Ctrl+Shift+P): run Go: Locate Configured Go Tools to check that the go binary path matches your terminal’s.

2. Align Dependencies Between Plugin and Main Program

Mismatched package versions (even minor ones) will trigger this error. Here’s how to sync them:

  • Navigate to both your main program directory (src/main) and the plugin directory (../mrapps)
  • Run go mod tidy in both locations to ensure all dependencies are locked to the same versions.
  • If you’re using GOPATH instead of Go modules, make sure both directories rely on identical copies of all dependency packages (no conflicting versions in your GOPATH).

3. Match Compilation Flags

You compiled your plugin with -race:

go build -race -buildmode=plugin ../mrapps/wc.go

Race detection instrumentation adds special code to the plugin, so your main program must also be compiled with -race to load it. Update your VS Code launch.json to include this flag:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch mrworker",
      "type": "go",
      "request": "launch",
      "mode": "debug",
      "program": "src/main/mrworker.go",
      "args": ["wc.so"],
      "buildFlags": "-race"
    }
  ]
}

Alternatively, if you don’t need race detection right now, recompile the plugin without -race and remove the flag from your debug config.

4. Clean Up Old Build Artifacts and Cache

Stale cache or old plugin files can cause hidden mismatches:

  • Delete the existing wc.so file
  • Clear Go’s build cache:
    go clean -cache
    
  • Recompile the plugin from scratch with your aligned environment.

5. Test with Direct dlv Execution (Bypass VS Code)

To rule out VS Code config issues, try debugging directly with dlv in your terminal:

  1. Compile the main program with matching flags:
    go build -race -o mrworker src/main/mrworker.go
    
  2. Start the debugger:
    dlv exec ./mrworker wc.so
    

If this works, the problem is in your VS Code launch configuration—double-check the program path and build flags.


内容的提问来源于stack exchange,提问作者whogetsthat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 08:37:40