你说的“Ubuntu 配 C++ 插件”通常有几种常见含义,我分别说明,你可以对号入座:
如果你是在 Ubuntu 上使用 VS Code 写 C++,步骤如下:
sudo apt update
sudo apt install build-essential gdb
验证:
gcc --version
g++ --version
sudo apt install code
或从官网下载 .deb 安装。
在 VS Code 扩展商店搜索并安装:
tasks.json(编译)按 Ctrl+Shift+P → Tasks: Configure Task → g++ build
示例:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": ["-g", "main.cpp", "-o", "main"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
launch.json(调试){
"version": "0.2.0",
"configurations": [
{
"name": "C++ Debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main",
"miDebuggerPath": "/usr/bin/gdb",
"preLaunchTask": "build"
}
]
}
如果你是写 C++ 插件给主程序调用:
// plugin.cpp
extern "C" {
void hello() {
printf("Hello from plugin!\n");
}
}
g++ -shared -fPIC plugin.cpp -o libplugin.so
#include <dlfcn.h>
void* handle = dlopen("./libplugin.so", RTLD_LAZY);
void (*hello)() = (void(*)())dlsym(handle, "hello");
hello();
dlclose(handle);
编译主程序:
g++ main.cpp -ldl -o main
如果你指的是某个具体软件(比如 Vim、Qt Creator、CLion、Unreal、ROS),告诉我名字,我可以给你专门步骤。
你可以告诉我:
我可以直接给你最短可跑方案。