开发者社区> 问答> 正文

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

a123456678 2016-06-07 18:20:03 2406

我的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
C++ Python
分享到
取消 提交回答
全部回答(1)

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题