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

Node.js C/C++ Addon构建报错LNK1103:调试信息损坏

Node.js C/C++ Addon编译LNK1103错误解决方法

我尝试为Node.js应用开发C/C++ Addon,编写了以下代码文件,但执行node-gyp configure build时遇到调试信息损坏的链接错误,具体代码和错误信息如下:


代码文件

addon.cpp

#include <node.h>
#include "src/prova.h"

namespace hellons {
    using v8::FunctionCallbackInfo;;
    using v8::Isolate;
    using v8::Local;
    using v8::Object;
    using v8::Value;
    using v8::String;

    void method1 (const FunctionCallbackInfo<Value>&args) {
        Isolate* isolate = args.GetIsolate();
        int result = hello();
        args.GetReturnValue().Set(result);
    }

    void Initialize (Local<Object> exports) {
        NODE_SET_METHOD(exports, "method1", method1);
    }

    NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize);
}

src/prova.h

int hello(void);

src/prova.cpp

int hello () {
    return 4;
}

binding.gyp

{
    "targets": [
        {
            "target_name": "addon",
            "sources": ["addon.cpp", "src/prova.h", "src/prova.cpp"],
            "include_dirs": [".", "src"]
        }
    ]
}

编译错误信息

执行node-gyp configure build后输出错误:

kernel32.lib(KERNEL32.dll) : fatal error LNK1103: debugging information corrupt; recompile module [C:\xampp\htdocs\xxx\yyy\build\addon.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\xampp\htdocs\xxx\yyy\node_modules\node-gyp\lib\build.js:203:23)
gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
gyp ERR! System Windows_NT 10.0.19045
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\xampp\\htdocs\\xxx\\yyy\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "build"
gyp ERR! cwd C:\xampp\htdocs\xxx\yyy
gyp ERR! node -v v16.10.0
gyp ERR! node-gyp -v v9.3.1
gyp ERR! not ok 

解决方法

按优先级尝试以下方案:

  • 清理编译缓存重构建

    1. 删除项目根目录下的build文件夹
    2. 执行node-gyp clean清理缓存
    3. 重新运行node-gyp configure build
  • 修正binding.gyp配置
    头文件无需加入sources列表,同时添加配置禁用调试信息生成:

    {
        "targets": [
            {
                "target_name": "addon",
                "sources": ["addon.cpp", "src/prova.cpp"],
                "include_dirs": [".", "src"],
                "msvs_settings": {
                    "VCCLCompilerTool": {
                        "DebugInformationFormat": 0
                    }
                }
            }
        ]
    }
    
  • 使用Release模式构建
    执行node-gyp configure build --release,跳过调试信息生成流程。

  • 修复Visual Studio组件
    打开Visual Studio Installer,检查并确保安装了"C++调试工具"组件;若已安装,尝试执行Visual Studio的修复安装,修复可能损坏的系统库调试文件。

  • 更新或降级node-gyp
    执行npm install -g node-gyp更新全局node-gyp;若仍有问题,可尝试降级到与Node.js v16兼容的v8.4.1版本:npm install -g node-gyp@8.4.1

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 15:32:24