nodejs / node-gyp

Node.js native addon build tool
MIT License
9.8k stars 1.78k forks source link

Fatal link error when trying to build a module with lib dependancy on Win10 #1394

Closed jimcarst closed 5 years ago

jimcarst commented 6 years ago

Hi,

Currently I am trying to get my own node module to work with the or-tools library from Google (https://github.com/google/or-tools).

In doing so, I use the following binding.gyp file:

{
    "targets": [{
        "target_name": "module",
      "sources": [ "src/module.cc", "src/module_tsp.cc", "src/module_tsp.h" ],
        'include_dirs': ["src", "src/or-tools2/include"],
        'link_settings': {
            'libraries': [
        '<(module_root_dir)/or-tools2/lib/ortools', ],
        },
        "libraries": [
            "ortools.lib",
        ], 
    }]
}

However, this leads to the following error:

PS C:\Users\...\Documents\...\repos\platform> node-gyp configure build
gyp info it worked if it ends with ok
gyp info using node-gyp@3.6.2
gyp info using node@8.10.0 | win32 | x64
gyp info spawn C:\Python\Python27\python.EXE
gyp info spawn args [ 'C:\\...\\AppData\\Roaming\\npm\\node_modules\\node-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=2015',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\...\\Documents\\...\\repos\\platform\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\...\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\...\\.node-gyp\\8.10.0\\include\\node\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\...\\.node-gyp\\8.10.0',
gyp info spawn args   '-Dnode_gyp_dir=C:\\...\\AppData\\Roaming\\npm\\node_modules\\node-gyp',
gyp info spawn args   '-Dnode_lib_file=C:\\...\\.node-gyp\\8.10.0\\<(target_arch)\\node.lib',
gyp info spawn args   '-Dmodule_root_dir=C:\\...\\Documents\\...\\repos\\platform',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'C:\\...\\Documents\\...\\repos\\platform\\build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe
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' ]
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
LINK : fatal error LNK1181: cannot open input file 'ortools.lib' [C:\Users\...\Documents\...\repos\platform\b
uild\module.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\...\AppData\Roaming\npm\node_modules\node-gyp\lib\build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "C:\\nodejs\\node.exe" "C:\\...\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "build"
gyp ERR! cwd C:\Users\...\Documents\...\repos\platform
gyp ERR! node -v v8.10.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok

Most important seems: LINK : fatal error LNK1181: cannot open input file 'ortools.lib'

It seems that somewhere the Windows specification of the filepath of the library is not working well.

Does anyone know how I can get this to work?

Regards

Skhoshhal commented 6 years ago

see these two issues https://stackoverflow.com/questions/21562038/node-gyp-build-error-windows-x64 https://yarnpkg.com/en/docs/envvars

rvagg commented 5 years ago

closing due to staleness, I assume this is either addressed by some other means or by the latest versions of node-gyp which have additional Windows work in them

franklevasseur commented 4 years ago

Currently having the exact same exception in windows 10... None of the links @Skhoshhal posted helped me...

I have no problem building my binding on ubuntu 18.04, but on windows it throws :

LINK : fatal error LNK1181: impossible d'ouvrir le fichier en entrÚe '.lib' [C:\Users\franc\Documents-franc\botpress-ro ot\node-svm2\build\node-svm.vcxproj]

(I'm a french canadian but it translates to same error)

Should I post a new issue?

cclauss commented 4 years ago

Please provide the log output like the original poster did. Merci.

franklevasseur commented 4 years ago

here it is

yarn build yarn run v1.16.0 $ node-gyp rebuild gyp info it worked if it ends with ok gyp info using node-gyp@6.1.0 gyp info using node@10.11.0 | win32 | x64 gyp info find Python using Python version 2.7.16 found at "C:\Python27\python.exe" gyp info find VS using VS2019 (16.4.29905.134) found at: gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools" gyp info find VS run with --verbose for detailed information gyp info spawn C:\Python27\python.exe gyp info spawn args [ 'C:\Users\franc\Documents-franc\botpress-root\node-svm2\node_modules\node-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 '-I', gyp info spawn args 'C:\Users\franc\Documents-franc\botpress-root\node-svm2\build\config.gypi', gyp info spawn args '-I', gyp info spawn args 'C:\Users\franc\Documents-franc\botpress-root\node-svm2\node_modules\node-gyp\addon.gypi', gyp info spawn args '-I', gyp info spawn args 'C:\Users\franc\AppData\Local\node-gyp\Cache\10.11.0\include\node\common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=C:\Users\franc\AppData\Local\node-gyp\Cache\10.11.0', gyp info spawn args '-Dnode_gyp_dir=C:\Users\franc\Documents-franc\botpress-root\node-svm2\node_modules\node-gyp', gyp info spawn args '-Dnode_lib_file=C:\\Users\\franc\\AppData\\Local\\node-gyp\\Cache\\10.11.0\\<(target_arch)\\node.lib', gyp info spawn args '-Dmodule_root_dir=C:\Users\franc\Documents-franc\botpress-root\node-svm2', gyp info spawn args '-Dnode_engine=v8', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'C:\Users\franc\Documents-franc\botpress-root\node-svm2\build', gyp info spawn args '-Goutput_dir=.' ] gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe 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' ] Les projets sont générés individuellement dans cette solution. Pour activer la génération en parallèle, ajoutez le commutateur "-m". nothing.vcxproj -> C:\Users\franc\Documents-franc\botpress-root\node-svm2\build\Release\nothing.lib svm.cpp main.cpp hello_world.cpp svm.cpp utils.cpp win_delay_load_hook.cc LINK : fatal error LNK1181: impossible d'ouvrir le fichier en entrÚe '.lib' [C:\Users\franc\Documents-franc\botpress-ro ot\node-svm2\build\node-svm.vcxproj] gyp ERR! build error gyp ERR! stack Error: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe failed with exit code: 1 gyp ERR! stack at ChildProcess.onExit (C:\Users\franc\Documents-franc\botpress-root\node-svm2\node_modules\node-gyp\lib\build.js:194:23) gyp ERR! stack at ChildProcess.emit (events.js:182:13) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12) gyp ERR! System Windows_NT 10.0.18362 gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\franc\Documents-franc\botpress-root\node-svm2\node_modules\node-gyp\bin\node-gyp.js" "rebuild" gyp ERR! cwd C:\Users\franc\Documents-franc\botpress-root\node-svm2 gyp ERR! node -v v10.11.0 gyp ERR! node-gyp -v v6.1.0 gyp ERR! not ok error Command failed with exit code 1.