开发者社区> 问答> 正文

node c++扩展引用引用静态库中函数提示 error LNK2001: 无法解析的外部符号 问题

最近在写一个node.js的扩展项目,发现了一个问题,我本来吧c代码在windows下做成一个静态库lib文件,可是在node.js扩展中调用其中的lib文件中的函数死活不能编译成功,报error LNK2001: 无法解析的外部符号。但是如果我不是用调用静态库的方式,直接把代码放入到node.js的扩展项目中一起编译竟能编译成功。我试了各种方法,死活找不到解决方法。
我出错时的gpy配置文件:

{
  "targets": [
    {
      "target_name": "shmdb",
      "include_dirs": [
        "include", "./include"
      ],
      'libraries': [
         '../lib/cshmdb.lib'
      ],

      "sources": [ "addon.cc","ShmdbObject.cc" ]
    }
  ]
}
编译出错时的日志:

正在创建库 D:\temp\addone\cpp2node\build\Release\shmdb.lib 和对象 D:\temp\addone\cpp2node\build\Release\shmdb.exp
ShmdbObject.obj : error LNK2001: 无法解析的外部符号 shmdb_initParent [D:\temp\addone\cpp2node\build\shmdb.vcxproj]
D:\temp\addone\cpp2node\build\Release\shmdb.node : fatal error LNK1120: 1 个无法解析的外部命令 [D:\temp\addone\cpp2node\build\shmdb.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `msbuild` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\sunny\AppData\Roaming\npm\no
de_modules\node-gyp\lib\build.js:267:23)
我的目录结构:
![screenshot](https://oss-cn-hangzhou.aliyuncs.com/yqfiles/2531298a6dc048975c9925b6cea2a8d47642ae45.png)

展开
收起
a123456678 2016-06-06 19:21:47 3383 0
1 条回答
写回答
取消 提交回答
  • 码农|Coder| Pythonista

    问题是链接的时候没有链接那个lib文件
    没用过gpy,一般用vs写c++程序的解决办法是直接在cpp里面写#pragma comment(lib,"xxx.lib")

    2019-07-17 19:29:18
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
使用C++11开发PHP7扩展 立即下载
GPON Class C++ SFP O;T Transce 立即下载
GPON Class C++ SFP OLT Transce 立即下载