你这个问题有点模糊,我先按最常见的两种“Ubuntu 配 C++ 插件”场景来解释,你可以看哪个符合你的需求:
如果你是 用 VS Code 写 C++,步骤如下:
sudo apt update
sudo apt install build-essential gdb
build-essential:包含 gcc / g++ / makegdb:调试用sudo apt install code
或从官网下载 .deb
打开 VS Code → 扩展(Ctrl+Shift+X)→ 搜索:
创建 test.cpp:
#include <iostream>
using namespace std;
int main() {
cout << "Hello Ubuntu" << endl;
}
编译运行:
g++ test.cpp -o test
./test
如果你是 写 C++ 插件(动态链接库),例如主程序加载 .so 插件:
extern "C" {
void hello() {
printf("Hello from plugin!\n");
}
}
g++ -shared -fPIC plugin.cpp -o libplugin.so
#include <dlfcn.h>
int main() {
void* handle = dlopen("./libplugin.so", RTLD_LAZY);
void (*hello)() = (void(*)())dlsym(handle, "hello");
hello();
dlclose(handle);
}
编译主程序:
g++ main.cpp -o main -ldl
请补充一下:
我可以直接给你精确配置方案。