开发者社区> 问答> 正文

c++引用c函数时,报错误 error LNK2001: 无法解析的外部符号

我的c头文件是这么写的

#ifdef __cplusplus 
extern "C" { 
#endif

extern int shmdb_initParent(STHashShareHandle *handle,unsigned int size);

#ifdef __cplusplus 
} 
#endif 
我的c++代码是这么写的

//引用头文件
extern "C" {
#include "mm.h"
}
//调用代码
int rv = shmdb_initParent(&obj->_handle,obj->counter_);
然后编译c++代码的时候被报出错误

int rv = shmdb_initParent(&obj->_handle,obj->counter_);
编译错误信息:

D:\temp\addone\cpp2node>node-gyp configure build --msvs_version=2012
gyp info it worked if it ends with ok
gyp info using node-gyp@0.13.0
gyp info using node@0.10.17 | win32 | x64
gyp info spawn python
gyp info spawn args [ 'C:\\Users\\sunny\\AppData\\Roaming\\npm\\node_modules\\no
de-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-G',
gyp info spawn args   'msvs_version=2012',
gyp info spawn args   '-I',
gyp info spawn args   'D:\\temp\\addone\\cpp2node\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\sunny\\AppData\\Roaming\\npm\\node_modules\\no
de-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\sunny\\.node-gyp\\0.10.17\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\sunny\\.node-gyp\\0.10.17',
gyp info spawn args   '-Dmodule_root_dir=D:\\temp\\addone\\cpp2node',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'D:\\temp\\addone\\cpp2node\\build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn msbuild
gyp info spawn args [ 'build/binding.sln',
gyp info spawn args   '/clp:Verbosity=minimal',
gyp info spawn args   '/nologo',
gyp info spawn args   '/p:Configuration=Release;Platform=x64' ]
在此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m”开关。
LINK : fatal error LNK1181: 无法打开输入文件“lib\shmdb.lib” [D:\temp\addone\cp
p2node\bu
ild\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)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:
12)
gyp ERR! System Windows_NT 6.2.9200
gyp ERR! command "node" "C:\\Users\\sunny\\AppData\\Roaming\\npm\\node_modules\\
node-gyp\\bin\\node-gyp.js" "configure" "build" "--msvs_version=2012"
gyp ERR! cwd D:\temp\addone\cpp2node
gyp ERR! node -v v0.10.17
gyp ERR! node-gyp -v v0.13.0
gyp ERR! not ok

展开
收起
a123456678 2016-06-07 18:20:03 6014 0
1 条回答
写回答
取消 提交回答
  • 动态加载dll

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

相关电子书

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

相关镜像