Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem Building Node (had errors about multiply-defined symbols and such) #24448

Closed
DragonOsman opened this issue Nov 17, 2018 · 31 comments
Closed
Labels
build Issues and PRs related to build files or the CI. question Issues that look for answers. windows Issues and PRs related to the Windows platform. zlib Issues and PRs related to the zlib subsystem.

Comments

@DragonOsman
Copy link

  • Version: Currently 11.1.0, but am installing 11.2.0
  • Platform: Windows 10 Home Single Language
  • Subsystem: Need to build Node (pulled from Node GitHub repo)

I went into my Node root with the .git folder and ran .\vcbuild, and it built a lot of the stuff but then ended with the errors:

zlib.lib(adler32.obj) : error LNK2005: adler32 already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(adler32.obj) : error LNK2005: adler32_combine already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(adler32.obj) : error LNK2005: adler32_z already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(crc32.obj) : error LNK2005: crc32 already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(crc32.obj) : error LNK2005: crc32_combine already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(crc32.obj) : error LNK2005: crc32_z already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(crc32.obj) : error LNK2005: get_crc_table already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
C:\node\Release\node.exe : fatal error LNK1169: one or more multiply defined symbols found [C:\node\node.vcxproj]

I want to build Node and then V8. Any help would be greatly appreciated.

@refack
Copy link
Contributor

refack commented Nov 17, 2018

Hello @DragonOsman and thank you for the report.
It seems like you computer has a previously installed zlib1.dll, and it's added the the linker's LIBPATH so it finds two library files that defines those symbols (your zlib1.dll and the zlib.lib we build from our tree).

  1. One option is to disable you globally installed zlib (it's usually installed with Chocolatery or NuGet)
  2. Another option is to run the configure script with --shared-zlib:
python configure --shared-zlib --with-pch --dest-cpu=x64 --verbose
                 ^^^^^^^^^^^^^

@refack refack added question Issues that look for answers. windows Issues and PRs related to the Windows platform. build Issues and PRs related to build files or the CI. zlib Issues and PRs related to the zlib subsystem. labels Nov 17, 2018
@DragonOsman
Copy link
Author

Thanks for the reply. I'll try the second option.

By the way, I forgot to mention earlier that I'm using Visual Studio 2017 (latest version).

@DragonOsman
Copy link
Author

DragonOsman commented Nov 17, 2018

I have these warnings:

rand_egd.obj : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library [C:\node\deps\openssl\openssl.vcxproj]
ecp_nistputil.obj : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library [C:\node\deps\openssl\openssl.vcxproj]
ecp_nistp521.obj : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library [C:\node\deps\openssl\openssl.vcxproj]
ecp_nistp256.obj : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library [C:\node\deps\openssl\openssl.vcxproj]
ecp_nistp224.obj : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library [C:\node\deps\openssl\openssl.vcxproj]
ebcdic.obj : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library [C:\node\deps\openssl\openssl.vcxproj]

Do I need to worry?

@refack
Copy link
Contributor

refack commented Nov 17, 2018

Do I need to worry?

No, it's expected. I often see it while building locally.

@DragonOsman
Copy link
Author

I got the same errors again:

zlib.lib(adler32.obj) : error LNK2005: adler32 already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(adler32.obj) : error LNK2005: adler32_combine already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(adler32.obj) : error LNK2005: adler32_z already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(crc32.obj) : error LNK2005: crc32 already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(crc32.obj) : error LNK2005: crc32_combine already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(crc32.obj) : error LNK2005: crc32_z already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(crc32.obj) : error LNK2005: get_crc_table already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
C:\node\Release\node.exe : fatal error LNK1169: one or more multiply defined symbols found [C:\node\node.vcxproj]

How do I disable the other zlib installation?

@refack
Copy link
Contributor

refack commented Nov 17, 2018

You can try:
image

@DragonOsman
Copy link
Author

I had zlib installed in the C drive in a folder called "libraries". I completely deleted that folder and then tried to build Node again, but had the same errors as before.

@refack
Copy link
Contributor

refack commented Nov 17, 2018

2. Another option is to run the configure script with --shared-zlib:

python configure --shared-zlib --with-pch --dest-cpu=x64 --verbose
                 ^^^^^^^^^^^^^

What I forgot to say is that if you build with vcbuild.bat then you need to set an env var config_flags. So:

set config_flags=--shared-zlib
vcbuild release x64

@DragonOsman
Copy link
Author

I even removed the vcpkg for zlib from my system and tried to build again with the commands you just gave. Got these errors at the end:

LINK : fatal error LNK1181: cannot open input file 'z.lib' [C:\node\tools\icu\icupkg.vcxproj]
LINK : fatal error LNK1181: cannot open input file 'z.lib' [C:\node\tools\icu\iculslocs.vcxproj]
LINK : fatal error LNK1181: cannot open input file 'z.lib' [C:\node\tools\icu\genccode.vcxproj]
LINK : fatal error LNK1181: cannot open input file 'z.lib' [C:\node\tools\icu\genrb.vcxproj]

Any ideas?

@refack
Copy link
Contributor

refack commented Nov 17, 2018

Any ideas?

So it's either/or. If you removed the global zlib.dll you need to build the "in tree" version (i.e. "not share zlib"):

set config_flags=
vcbuild release x64

If that doesn't work, try searching your whole computer for zlib.dll and rename them all.

@DragonOsman
Copy link
Author

DragonOsman commented Nov 18, 2018

Got the same errors.

So what do you mean by renaming them all? What should I rename them to? And what if I just delete them all?

I wonder if you could help me with compiling a C++ webserver app I have to WebAssembly? I want to use it on the backend as a Node.js module. I can't get em++ to generate .wasm code for it, though. I get .o and .js, but no .wasm. The source code is here: https://github.com/DragonOsman/currency_converter , and the command I used is:

em++ -std=c++17 -Wall -pedantic -D variant_CONFIG_SELECT_VARIANT=variant_VARIANT_NONSTD -I C:/Jinja2Cpp/install_x64/include -I C:/json/single_include -I C:/boost_1_68_0/ -I C:/Users/Osman/emsdk/emscripten/1.38.18/system/include/ currency_converter.cpp -L C:/Jinja2Cpp/install_x64/lib/static/jinja2cpp.lib -L C:/boost_1_68_0/lib64-msvc-14.1/libboost_system-vc141-mt-x64-1_68.lib -lpthread -o currency_converter.js -o currency_converter.o currency_converter.js -s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0 -s USE_PTHREADS=1

I understand that when wanting to call embind for std::shared_ptr in JavaScript code, one has to use EMSCRIPTEN_BINDINGS and some other code in there to be able to do it. Does this apply to Node.js? Could this be why it won't generate WebAssembly code? If so, how do I use EMSCRIPTEN_BINDINGS on std::make_shared_from_this<>? I want to use the one that will let the pointer translate to an actual std::shared_ptr on the Node.js side rather than a regular, raw pointer.

I also tried asking about this in the emsdk GitHub. That's here (the two replies there is just me giving more info and updates) and here. I also asked something else two months ago about cwrap, and I asked about this there as well: link. As you can see, I don't have replies on the latest comments I made. If you can help me on this, that'd be great.

Note: The "same errors" I mentioned before are the same ones I was getting at first:

zlib.lib(adler32.obj) : error LNK2005: adler32 already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(adler32.obj) : error LNK2005: adler32_combine already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(adler32.obj) : error LNK2005: adler32_z already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(crc32.obj) : error LNK2005: crc32 already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(crc32.obj) : error LNK2005: crc32_combine already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(crc32.obj) : error LNK2005: crc32_z already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
zlib.lib(crc32.obj) : error LNK2005: get_crc_table already defined in zlib.lib(zlib1.dll) [C:\node\node.vcxproj]
C:\node\Release\node.exe : fatal error LNK1169: one or more multiply defined symbols found [C:\node\node.vcxproj]

@DragonOsman
Copy link
Author

I got these errors again when I tried to build with shared-zlib flag:

LINK : fatal error LNK1181: cannot open input file 'z.lib' [C:\node\tools\icu\icupkg.vcxproj]
LINK : fatal error LNK1181: cannot open input file 'z.lib' [C:\node\tools\icu\iculslocs.vcxproj]
LINK : fatal error LNK1181: cannot open input file 'z.lib' [C:\node\tools\icu\genccode.vcxproj]
LINK : fatal error LNK1181: cannot open input file 'z.lib' [C:\node\tools\icu\genrb.vcxproj]

How do I fix this error?

@DragonOsman
Copy link
Author

DragonOsman commented Nov 18, 2018

I don't have zlib1.dll anymore, but I still had those errors about it when I tried to build without the --shared-zlib flag. I'm trying again after cleaning the build.

Edit: Still got the same errors. I deleted the node folder cloned into it again, and am trying to build it again, but I don't know if I should expect much since I already tried this before with no luck. And this time, I also have warnings about these two input files being missing:

tools\msvs\genfiles\node_etw_provider.rc
tools\msvs\genfiles\node_etw_provider.h

@DragonOsman
Copy link
Author

DragonOsman commented Nov 18, 2018

I had errors about zlib1.dll again even though it doesn't even exist anymore. I searched in my C drive where all of the stuff should be, and it said it found no matches. What should I do?

@DragonOsman
Copy link
Author

@refack I have node.lib and zlib.lib in my node installation. Has it already been built despite those errors, then? Or do I still need more .lib files than the ones I have (I see 21 .lib files)?

And does building Node also build V8, or do I still need to build it?

@Trott
Copy link
Member

Trott commented Nov 24, 2018

And does building Node also build V8, or do I still need to build it?

Building Node.js will build V8 as a prerequisite.

@refack
Copy link
Contributor

refack commented Nov 25, 2018

Hi @DragonOsman did you make any progress, or have any new insights.

@DragonOsman
Copy link
Author

I need advice on what to rename zlib1.dll into. I have lots of instances of it; some in vcpkg's files, some in Visual Studio 2017's files. If I try to set the --shared-zlib flag, I get a linker error saying that it can't open z.lib.

@DragonOsman
Copy link
Author

DragonOsman commented Nov 27, 2018

I tried to run this command to try to build it this way:

vcbuild release x64 build-release no-cctest static

But I keep getting this message:

Looking for WiX installation for Visual Studio 2017...
Failed to find WiX install for Visual Studio 2017
VS2017 support for WiX is only present starting at version 3.11
Failed to find a suitable Visual Studio installation.
Try to run in a "Developer Command Prompt" or consult
https://github.com/nodejs/node/blob/master/BUILDING.md#windows-1

even after I both installed WiX and added it to the PATH, and also installed a Visual Studio 2017 Extension for WiX. Do I put WiX as the first thing mentioned in the PATH, or is that not a problem?

@DragonOsman
Copy link
Author

I think I'll just run the fetch v8 command and get only V8, that way. And quit trying to build all of Node.js since it's giving me trouble because of zlib.

@Trott
Copy link
Member

Trott commented Nov 29, 2018

@nodejs/platform-windows ☝️

@DragonOsman
Copy link
Author

DragonOsman commented Nov 30, 2018

I have zlib dll instances in vcpkg and VS2017 installation directories, and I've also built zlib myself. I want to know if it's possible to just use the zlib I built myself with Node and just make Node ignore the one inside its source tree. Is this possible, and if so, how do I do it?

I mainly just want V8, so I've also been trying to build it. Haven't had any luck. I'm using VS2017 and have tried to follow the instructions here: https://medium.com/dailyjs/how-to-build-v8-on-windows-and-not-go-mad-6347c69aacd4 because the ones on the main documentation for V8 also didn't really help. But I got errors when I ran the command mentioned there, I got this error message:

Hint: You can raise verbosity (-vv) to see the output of failed commands.

Traceback (most recent call last):
  File "C:\v8\tools\dev\v8gen.py", line 304, in <module>
    sys.exit(gen.main())
  File "C:\v8\tools\dev\v8gen.py", line 298, in main
    return self._options.func()
  File "C:\v8\tools\dev\v8gen.py", line 166, in cmd_gen
    gn_outdir,
  File "C:\v8\tools\dev\v8gen.py", line 208, in _call_cmd
    stderr=subprocess.STDOUT,
  File "C:\Python27\lib\subprocess.py", line 223, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['C:\\Python27\\python.exe', '-u', 'tools\\mb\\mb.py', 'gen', '-f', 'infra\\mb\\mb_config.pyl', '-m', 'developer_default', '-b', 'x64.release', 'out.gn/x64.release']' returned non-zero exit status 1

The command I ran was: python tools/dev/v8gen.py x64.release. I also tried going inside the tools/dev directory and executing it there, though I left out the python command from the beginning of it. Same result.

When I try to follow the instructions on the official documentation, it tries to run the termios module which of course it can't because it's not there on Windows.

@Trott Why did you post that? Is there something for me to do there?

@DragonOsman
Copy link
Author

I still need to try building it with the Release configuration, since I've only tried with the Debug one so far, but it seems choosing dll in the vcbuild arguments, instead of static, did it. I still have .lib files, though. I didn't set build-release, and built it manually using the IDE itself. IIRC (I already closed the command prompt window I did it in, so I'll have to say from memory), the command I ran was vcbuild release no-cctest x64 dll. I may have gotten the order wrong on some of that, but that's the gist of it. And I still managed to build cctest even though I'd put no-cctest. Also, I'm not sure if it made a difference, but I build node.vcxproj first.

@DragonOsman
Copy link
Author

Update to above post: Turns out that although it worked with the Debug configuration, it didn't work with the Release configuration. I get "undefined symbol" errors because of zlib1.dll when I try to build node.vcxproj. I do have node.lib and zlib.lib in my Release/lib directory, though.

Again, I'd like to know how I can make it ignore those zlib1.dlls and use the zlib I built myself. If this possible, I'd really like to know how to do it. Thanks in advance.

@DragonOsman
Copy link
Author

DragonOsman commented Dec 1, 2018

Is there a way for me to provide the path to the zlib I built when trying to use shared-zlib? So that it doesn't look for z.lib (I have zlib.lib and zlibstatic.lib, and I built the latest version of zlib).

Edit to add: I put in the path to the zlib include and lib directories in the project property pages, and also put in zlib.lib as the input file name for the linker to look for. I'm trying to build node.vcxproj again now.

@DragonOsman
Copy link
Author

In the node.vcxproj linker command line, it has `C:/node/lib/Release/node.lib" as one of the linker input files. Why? I don't even see it under the linker input settings under "Linker" in Project Properties, so I don't know how to take it out of there. It's causing the project to fail to build. I asked on MSDN forums here, as well: link . Originally it was to ask about how to add library input files to the linker command line, but I decided to ask about this there, as well.

@Trott
Copy link
Member

Trott commented Dec 4, 2018

@nodejs/build

@DragonOsman
Copy link
Author

DragonOsman commented Dec 6, 2018

I tried specifying static and nobuild for vcbuild when generating project files and then tried to build the other projects before the main node.vcxproj one. But node.vcxproj keeps failing with linker errors. I have the log file. Gist link: https://gist.github.com/DragonOsman/ea32bd66414064d5c390854ce3ac1db2 . The reason it's so long with so much info is because I chose the setting for the most detailed diagnostic in MSBuild. It gives you info on the whole build environment everything too, not just on the build information.

Anyway, I'd really like some help here.

I already have this issue where I'm asking about this (in the Nodejs Help repo): nodejs/help#1656

@DragonOsman
Copy link
Author

I downloaded the source code for version 11.6.0 from the Nodejs website and tried to build it (directly using IDE GUI). Before running vcbuild, I ran this command:

set config_flags=--shared-zlib --shared-zlib-libname=zlibstatic.lib --shared-zlib-libpath="C:\\zlib_library\\lib" --shared-zlib-includes="C:\\zlib_library\\include" --fully-static --with-ltcg --dest-cpu=x64 --without-etw

And then I ran vcbuild like this:

.\vcbuild release static vs2017 noetw ltcg no-cctest nobuild

Most of it builds successfully, but I have these linker errors when I try to build node.vcxproj:


39>zlibstatic.lib(gzlib.obj) : error LNK2001: unresolved external symbol __imp_open
39>OLDNAMES.lib(open.obi) : error LNK2001: unresolved external symbol __imp_open
39>zlibstatic.lib(gzread.obj) : error LNK2001: unresolved external symbol __imp_read
39>OLDNAMES.lib(read.obi) : error LNK2001: unresolved external symbol __imp_read
39>zlibstatic.lib(gzwrite.obj) : error LNK2001: unresolved external symbol __imp_write
39>OLDNAMES.lib(write.obi) : error LNK2001: unresolved external symbol __imp_write
39>C:\node-v11.6.0\Release\node.exe : fatal error LNK1120: 3 unresolved externals

What library am I missing? Could someone please help me out? Thanks in advance.

@jasnell
Copy link
Member

jasnell commented Jun 19, 2020

There's been no further activity on this. Closing. Can reopen if necessary

@congzhangzh
Copy link
Contributor

@DragonOsman I think you can do vcpkg integration remove, and then it should work, this works for me
Tips: even if you do not install vcpkg yourself, Visual Studio may install automate as it's part of Visual Studio solution

vcpkg integration remove

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. question Issues that look for answers. windows Issues and PRs related to the Windows platform. zlib Issues and PRs related to the zlib subsystem.
Projects
None yet
Development

No branches or pull requests

5 participants