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

VS Code C/C++ Compile Run扩展编译错误求助(Cygwin64+Win7)

Cygwin64 + VS Code C/C++ Compile Run 编译共享库加载失败问题

在Windows 7系统下,使用Cygwin64编译器,通过VS Code的C/C++ Compile Run扩展编译代码时,按下F6触发编译后出现错误:

"...cygwin64/lib/gcc/x86_64-pc-cygwin11/cc1plus.exe:error while loading shared libraries: ?: cannot open shared object file: No such file or directory"

扩展设置

{
    "C_Cpp.default.compilerPath": "E:\\cygwin64\\bin\\gcc.exe",
    "editor.renderWhitespace": "all",
    "terminal.integrated.defaultProfile.windows": "PowerShell",
    "window.zoomLevel": 1,
    "C_Cpp.files.exclude": {
        
        "**/.vscode": true,
        "**/.vs": true
    },
    "terminal.integrated.useWslProfiles": false,
    "terminal.integrated.profiles.windows": {

        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "Git Bash": {
            "source": "Git Bash"
        },
        "Cygwin": { 
            "path": "E:\\cygwin64\\bin\\mintty.exe",
            "args": ["-"],
            "icon": "terminal-cmd",
            "name": "Cygwin"
        }
    },
    "terminal.integrated.cwd": ".../Cproject",
    "terminal.integrated.defaultProfile.osx": "",
    "c-cpp-compile-run.cpp-compiler": "E:/cygwin64/bin/g++.exe",
    "c-cpp-compile-run.c-compiler": "E:/cygwin64/bin/gcc.exe"
}

已加载的库信息

ntdll.dll => /cygdrive/c/Windows/SYSTEM32/ntdll.dll (0x77930000)
        kernel32.dll => /cygdrive/c/Windows/system32/kernel32.dll (0x77810000)
        KERNELBASE.dll => /cygdrive/c/Windows/system32/KERNELBASE.dll (0x7fefd630000)
        cygwin1.dll => /usr/bin/cygwin1.dll (0x7fed81a0000)
        cyggmp-10.dll => /usr/bin/cyggmp-10.dll (0x3ff7b0000)
        cygiconv-2.dll => /usr/bin/cygiconv-2.dll (0x3ff670000)
        cygintl-8.dll => /usr/bin/cygintl-8.dll (0x3ff640000)
        cygisl-23.dll => /usr/bin/cygisl-23.dll (0x3fe960000)
        cygmpc-3.dll => /usr/bin/cygmpc-3.dll (0x3fe930000)
        cygmpfr-6.dll => /usr/bin/cygmpfr-6.dll (0x3ff490000)
        cyggcc_s-seh-1.dll => /usr/bin/cyggcc_s-seh-1.dll (0x3ff870000)
        cygz.dll => /usr/bin/cygz.dll (0x3fedc0000)
        cygzstd-1.dll => /usr/bin/cygzstd-1.dll (0x3fed10000)

Cygwin已安装包

curl 8.2.1-1
gcc-core 11.4.0-1
gcc-g++ 11.4.0-1
gdb 12.1-1
git 2.39.0-1
libSDL-devel 1.2.15-3
libopencv-devel 3.4.1-3
make 4.4.1-2
wget 1.21.4-1
zip 3.0-13

已尝试的解决方法

  • 重装Cygwin
  • 重装C/C++ Compile Run扩展
  • 检查系统环境变量PATH

可行解决方案

1. 调整系统PATH优先级

打开系统环境变量设置,将E:\cygwin64\bin移到PATH列表的最顶部,避免其他环境中的库干扰Cygwin的库加载逻辑。

2. 切换VS Code默认终端为Cygwin

修改VS Code设置,将默认终端改为Cygwin,确保编译命令在Cygwin环境中执行:

"terminal.integrated.defaultProfile.windows": "Cygwin"

3. 定位缺失的依赖库

打开Cygwin终端,执行以下命令查看cc1plus.exe的完整依赖:

cd /cygdrive/e/cygwin64/lib/gcc/x86_64-pc-cygwin11
ldd cc1plus.exe

输出中标记为not found的库即为缺失项,通过Cygwin安装器搜索并安装对应的包。

4. 修复Cygwin编译包

运行Cygwin安装器,选择"Reinstall"模式,重新安装gcc-core和gcc-g++包,确保所有依赖组件完整安装。

5. 手动指定库路径

在VS Code的C/C++ Compile Run扩展设置中,添加编译参数指定Cygwin库路径:

"c-cpp-compile-run.cpp-flags": "-L E:/cygwin64/lib -L E:/cygwin64/usr/lib",
"c-cpp-compile-run.c-flags": "-L E:/cygwin64/lib -L E:/cygwin64/usr/lib"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 10:17:49