0

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.

4
  • Have you put all the c files in the static lib? (fatal error LNK1120 is an unresolved external, right?)
    – doctorlove
    Sep 25, 2014 at 14:53
  • Yes,error LNK1120 means unresolved 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.
    – yunnysunny
    Sep 26, 2014 at 4:40
  • Did you solved it? How? Mar 29, 2017 at 15:40
  • Not solved. I had to put all source files of cshmdb.lib to my project to compile it.
    – yunnysunny
    Apr 3, 2017 at 12:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.