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

issue EthanHeilman openend this issue on March 26, 2023
  1. EthanHeilman commented at 3:41 am on March 26, 2023: contributor

    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

    0PS C:\Users\e0\Documents\GitHub\bitcoin> vcpkg install libevent                                                                        
    1warning: 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.
    2Computing installation plan...
    3The following packages are already installed:
    4    libevent[core,thread]:x86-windows -> 2.1.12+20230128
    5libevent:x86-windows is already installed
    6Restored 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:

    0    <Link>
    1      <SubSystem>Console</SubSystem>
    2      <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>
    3      <RandomizedBaseAddress>true</RandomizedBaseAddress>
    4    </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

     0PS C:\Users\e0\Documents\GitHub\bitcoin> msbuild build_msvc\bitcoin.sln -property:Configuration=Release -maxCpuCount -verbosity:minimal
     1MSBuild version 17.5.1+f6fdcf537 for .NET Framework
     2
     3  libunivalue.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libunivalue\libunivalue.lib
     4  libbitcoin_cli.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoin_cli\libbitcoin_cli.lib
     5  libbitcoin_zmq.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoin_zmq\libbitcoin_zmq.lib
     6  libsecp256k1.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libsecp256k1\libsecp256k1.lib
     7  libbitcoin_crypto.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoin_crypto\libbitcoin_crypto.lib
     8  libminisketch.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libminisketch\libminisketch.lib
     9  libbitcoin_wallet_tool.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoin_wallet_tool\libbitcoin_wallet_tool.lib
    10  libleveldb.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libleveldb\libleveldb.lib
    11  libbitcoinconsensus.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoinconsensus\libbitcoinconsensus.lib
    12  libbitcoin_util.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoin_util\libbitcoin_util.lib
    13  libtest_util.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libtest_util\libtest_util.lib
    14  httpserver.cpp
    15  libbitcoin_common.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoin_common\libbitcoin_common.lib
    16  libbitcoin_wallet.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\libbitcoin_wallet\libbitcoin_wallet.lib
    17  bitcoin-tx.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\bitcoin-tx.exe
    18  bitcoin-util.vcxproj -> C:\Users\e0\Documents\GitHub\bitcoin\build_msvc\x64\Release\bitcoin-util.exe
    19C:\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
    20.vcxproj]
    21C:\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]
    22C:\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]
    23C:\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]
    24     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
    25event.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]
    26C:\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]
    27  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 4c6b7d330a4e80460dcce19b1a0a47d77a0b99ea

    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

  2. hebasto referenced this in commit 026aadaea6 on Mar 27, 2023
  3. fanquake added the label Windows on Mar 27, 2023
  4. EthanHeilman referenced this in commit 6649bed1e0 on Mar 28, 2023
  5. EthanHeilman referenced this in commit 28436965b6 on Apr 3, 2023
  6. EthanHeilman referenced this in commit b2558a16f2 on Apr 5, 2023
  7. EthanHeilman referenced this in commit c40c9edf92 on Apr 5, 2023
  8. EthanHeilman referenced this in commit 6a9a4d13b2 on Apr 5, 2023
  9. fanquake referenced this in commit 06fb95b51b on Apr 6, 2023
  10. fanquake closed this on Apr 6, 2023

  11. sidhujag referenced this in commit e5f2992bfa on Apr 6, 2023
  12. RandyMcMillan referenced this in commit d777306ff6 on May 27, 2023
  13. bitcoin locked this on Apr 5, 2024


EthanHeilman

Labels
Windows


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-29 01:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me