Skip to content

Bitcoin fails to build on MSVC: Libevent and BCryptGenRandom errors  #27332

Closed

Description

@EthanHeilman

Is there an existing issue for this?

  • I have searched the existing issues

Current behaviour

When running msbuild build_msvc\bitcoin.sln -property:Configuration=Release -maxCpuCount -verbosity:minimal I get the following two errors in the build.

C:\Users\e0\Documents\GitHub\bitcoin\src\httpserver.cpp(637,9): error C2664: 'void evhttp_connection_get_peer(evhttp_connection *,const char **,uint16_t *)': cannot convert argument 2 from 'char **' to 'const char **' [C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\libbitcoin_node\libbitcoin_node .vcxproj]

event.lib(evutil_rand.c.obj) : error LNK2019: unresolved external symbol BCryptGenRandom referenced in function arc4_seed [C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\bitcoin-cli\bitcoin-cli.vcxproj]
C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\bitcoin-cli.exe : fatal error LNK1120: 1 unresolved externals [C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\bitcoin-cli\bitcoin-cli.vcxproj]`

Note that vcpkg believes that the latest stable version of libevent is installed

PS C:\Users\e0\Documents\GitHub\bitcoin> vcpkg install libevent                                                                        
warning: Starting with the September 2023 release, the default triplet for vcpkg libraries will change from x86-windows to the detected host triplet (x64-windows). To resolve this message, add --triplet x86-windows to keep the same behavior.
Computing installation plan...
The following packages are already installed:
    libevent[core,thread]:x86-windows -> 2.1.12+20230128
libevent:x86-windows is already installed
Restored 0 package(s) from C:\Users\e0\AppData\Local\vcpkg\archives in 98.5 us. Use --debug to see more details.

The error message is very similar to this issue #23606 which was resolved last year (Jan 13, 2022) with this PR: #23607

A theory: Given that the PR #23607 solves the issue by redefining evhttp_connection in configure.ac. I am speculating the configure.ac is not run for MSVC and thus PR #23607 does not solve this issue for MSCV. Further confirming this is if I add the line #define HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR to httpserver.cpp this evhttp_connection error no longer appears in the compiler out. However the BCryptGenRandom error still occurs.

Update-1:
I have solved the bcrypt errors by adding bcrypt as a dependency to the common.init.vcxproj with the following edit:

    <Link>
      <SubSystem>Console</SubSystem>
      <AdditionalDependencies>bcrypt.lib;Iphlpapi.lib;ws2_32.lib;Shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <RandomizedBaseAddress>true</RandomizedBaseAddress>
    </Link>

So at minimum this should be added to common.init.vcxproj.in so that python .\build_msvc\msvc-autogen.py will add this lib when it builds common.init.vcxproj.

With regards to to the evhttp_connection errors, msvc-autogen.py does not attempt to define HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR when it reads configure.ac. It might be reasonable to just assume that anyone doing an MSVC build will use vcpk and get the latest version of libevent and thus hardcode HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR in the config for msvc.

Update-2: I have created a PR to fix this.

Expected behaviour

Bitcoin compiles successfully

Steps to reproduce

I'm following the build instructions here: https://github.com/bitcoin/bitcoin/tree/master/build_msvc

  1. Download Bitcoin source code from master branch
  2. Install vcpkg and add vcpkg to path so that it actually works,
  3. Skip installing QT step and delete QT build targets from bitcoin.sln
  4. Run python build_msvc\msvc-autogen.py
  5. Run msbuild build_msvc\bitcoin.sln -property:Configuration=Release -maxCpuCount -verbosity:minimal
  6. Build fails with errors shown above

Relevant log output

PS C:\Users\e0\Documents\GitHub\bitcoin> msbuild build_msvc\bitcoin.sln -property:Configuration=Release -maxCpuCount -verbosity:minimal
MSBuild version 17.5.1+f6fdcf537 for .NET Framework

  libunivalue.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libunivalue\libunivalue.lib
  libbitcoin_cli.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoin_cli\libbitcoin_cli.lib
  libbitcoin_zmq.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoin_zmq\libbitcoin_zmq.lib
  libsecp256k1.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libsecp256k1\libsecp256k1.lib
  libbitcoin_crypto.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoin_crypto\libbitcoin_crypto.lib
  libminisketch.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libminisketch\libminisketch.lib
  libbitcoin_wallet_tool.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoin_wallet_tool\libbitcoin_wallet_tool.lib
  libleveldb.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libleveldb\libleveldb.lib
  libbitcoinconsensus.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoinconsensus\libbitcoinconsensus.lib
  libbitcoin_util.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoin_util\libbitcoin_util.lib
  libtest_util.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libtest_util\libtest_util.lib
  httpserver.cpp
  libbitcoin_common.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoin_common\libbitcoin_common.lib
  libbitcoin_wallet.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoin_wallet\libbitcoin_wallet.lib
  bitcoin-tx.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\bitcoin-tx.exe
  bitcoin-util.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\bitcoin-util.exe
C:\Users\e0\Documents\GitHub\bitcoin\src\httpserver.cpp(637,9): error C2664: 'void evhttp_connection_get_peer(evhttp_connection *,const char **,uint16_t *)': cannot convert argument 2 from 'char **' to 'const char **' [C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\libbitcoin_node\libbitcoin_node
.vcxproj]
C:\Users\e0\Documents\GitHub\bitcoin\src\httpserver.cpp(637,49): message : Conversion loses qualifiers [C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\libbitcoin_node\libbitcoin_node.vcxproj]
C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\vcpkg_installed\x64-windows-static\x64-windows-static\include\event2\http.h(1001,6): message : see declaration of 'evhttp_connection_get_peer' [C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\libbitcoin_node\libbitcoin_node.vcxproj]
C:\Users\e0\Documents\GitHub\bitcoin\src\httpserver.cpp(637,9): message : while trying to match the argument list '(evhttp_connection *, char **, uint16_t *)' [C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\libbitcoin_node\libbitcoin_node.vcxproj]
     Creating library C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\bitcoin-cli.lib and object C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\bitcoin-cli.exp
event.lib(evutil_rand.c.obj) : error LNK2019: unresolved external symbol BCryptGenRandom referenced in function arc4_seed [C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\bitcoin-cli\bitcoin-cli.vcxproj]
C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\bitcoin-cli.exe : fatal error LNK1120: 1 unresolved externals [C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\bitcoin-cli\bitcoin-cli.vcxproj]
  bitcoin-wallet.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\bitcoin-wallet.exe

How did you obtain Bitcoin Core

Compiled from source

What version of Bitcoin Core are you using?

bitcoin master branch at commit 4c6b7d3

Operating system and version

Windows 11 Pro Version 22H2 Installed on ‎2/‎18/‎2023 OS build 22621.1413 Experience Windows Feature Experience Pack 1000.22639.1000.0

Machine specifications

Processor 11th Gen Intel(R) Core(TM) i7-11700F @ 2.50GHz 2.50 GHz
Installed RAM 16.0 GB (15.9 GB usable)
System type 64-bit operating system, x64-based processor
Pen and touch No pen or touch input is available for this display

Activity

  1. linked a pull request that will close this issueFixes compile errors in MSVC build #27332 #27335on Apr 6, 2023
  2. added a commit that references this issue on Apr 6, 2023
  3. locked and limited conversation to collaborators on Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions