I found a problem when i wrote a node.js add-on. The description of the problem is:
I have built a static library (a lib file, named cshmdb.lib) from a C project. When I used it in a node.js's add-on project, it gave the error LNK2001 when building. But when i don't used the lib file, and put all the C file into the node.js's add-on project, it built successfully. The configuration of gpy when error occured is as follow:
{
"targets" : [
{
"target_name" : "shmdb",
"include_dirs" : [
"include", "./include"
],
'libraries' : [
'../lib/cshmdb.lib'
],
"sources" : ["addon.cc", "ShmdbObject.cc"]
}
]
}
The build error:
正在创建库 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)
My directory structure:
cpp2node
----include
----mm.h
----lib
----cshmdb.lib
----addone.cc
----building.gpy
----ShmdbObject.cc
----ShmdbObject.h
In addition , I wrote a test win32 console project and call the lib file cshmdb.lib in vs2012,and it built successfully. I guess that something was wrong when i configure the gpy, but I can't find the reason.
error LNK1120
meansunresolved external
.I have put all of c file into the static lib,i even wrote a test win32 console project to test the lib,and i ran ok.cshmdb.lib
to my project to compile it.