title: Error compiling openvpn3 in windows under mingw64- variable was not declared in scope
body: <p>I get this error trying to compile openvpn3 (<a href="https://github.com/OpenVPN/openvpn3" rel="nofollow noreferrer">https://github.com/OpenVPN/openvpn3</a>) in windows under mingw64</p>
  
  <pre><code>$ ./build.sh
  g++ -fwhole-program -O3 -Wall -Wno-sign-compare -Wno-unused-parameter -std=c++14 -flto=4 -Wl,--no-as-needed -Wno-unused-local-typedefs -Wno-unused-variable -Wno-shift-count-overflow -pthread -mms-bitfields -pthread -mms-bitfields -IC:/msys64/mingw64/include/gtk-3.0 -IC:/msys64/mingw64/include/cairo -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/pango-1.0 -IC:/msys64/mingw64/include/atk-1.0 -IC:/msys64/mingw64/include/cairo -IC:/msys64/mingw64/include/pixman-1 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/freetype2 -IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include/harfbuzz -IC:/msys64/mingw64/include/glib-2.0 -IC:/msys64/mingw64/lib/glib-2.0/include -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/freetype2 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/harfbuzz -IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include/gdk-pixbuf-2.0 -IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include/glib-2.0 -IC:/msys64/mingw64/lib/glib-2.0/include -IC:/msys64/mingw64/include -I/usr/include/jsoncpp -DUSE_OPENSSL -DUSE_ASIO -DASIO_STANDALONE -DASIO_NO_DEPRECATED -I/home/Nicholas/Work/asio/asio/include -DHAVE_LZ4 -I/home/Nicholas/Work/ovpn3/core ovpncli.cpp -o ovpncli -LC:/msys64/mingw64/lib -lgtk-3 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32 -lz -lpangowin32-1.0 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl -lcurlpp -lcurl -ljsoncpp -lssl -lcrypto -ldl -llz4
  In file included from C:/msys64/home/Nicholas/Work/ovpn3/core/openvpn/tun/win/client/tuncli.hpp:41:0,
                   from C:/msys64/home/Nicholas/Work/ovpn3/core/openvpn/client/cliopt.hpp:86,
                   from C:/msys64/home/Nicholas/Work/ovpn3/core/openvpn/client/cliconnect.hpp:59,
                   from C:/msys64/home/Nicholas/Work/ovpn3/core/client/ovpncli.cpp:96,
                   from ovpncli.cpp:35:
  C:/msys64/home/Nicholas/Work/ovpn3/core/openvpn/tun/win/client/tunsetup.hpp: In member function 'void openvpn::TunWin::Setup::adapter_config_l2(HANDLE, const wstring&amp;, const openvpn::TunWin::Util::TapNameGuidPair&amp;, const openvpn::TunBuilderCapture&amp;, openvpn::ActionList&amp;, openvpn::ActionList&amp;, std::ostream&amp;)':
  C:/msys64/home/Nicholas/Work/ovpn3/core/openvpn/tun/win/client/tunsetup.hpp:777:74: error: 'tap' was not declared in this scope
    l2_thread.reset(new std::thread([this, logwrap=Log::Context::Wrapper(), tap]() {
                                                                            ^~~
  C:/msys64/home/Nicholas/Work/ovpn3/core/openvpn/tun/win/client/tunsetup.hpp: In lambda function:
  C:/msys64/home/Nicholas/Work/ovpn3/core/openvpn/tun/win/client/tunsetup.hpp:783:26: error: 'tap' is not captured
     Util::dhcp_release(ii, tap.index, os);
                            ^~~
  C:/msys64/home/Nicholas/Work/ovpn3/core/openvpn/tun/win/client/tunsetup.hpp:777:77: note: the lambda has no capture-default
    l2_thread.reset(new std::thread([this, logwrap=Log::Context::Wrapper(), tap]() {
                                                                               ^
  C:/msys64/home/Nicholas/Work/ovpn3/core/openvpn/tun/win/client/tunsetup.hpp:777:74: note: '&lt;typeprefixerror&gt;tap' declared here
    l2_thread.reset(new std::thread([this, logwrap=Log::Context::Wrapper(), tap]() {
                                                                            ^~~
  C:/msys64/home/Nicholas/Work/ovpn3/core/openvpn/tun/win/client/tunsetup.hpp:789:24: error: 'tap' is not captured
     Util::dhcp_renew(ii, tap.index, os);
                          ^~~
  C:/msys64/home/Nicholas/Work/ovpn3/core/openvpn/tun/win/client/tunsetup.hpp:777:77: note: the lambda has no capture-default
    l2_thread.reset(new std::thread([this, logwrap=Log::Context::Wrapper(), tap]() {
                                                                               ^
  C:/msys64/home/Nicholas/Work/ovpn3/core/openvpn/tun/win/client/tunsetup.hpp:777:74: note: '&lt;typeprefixerror&gt;tap' declared here
    l2_thread.reset(new std::thread([this, logwrap=Log::Context::Wrapper(), tap]() {
                                                                        ^~~
  </code></pre>
  
  <p>I looked at the header file that is causing the error, and <code>tap</code> is defined in the function parameters</p>
  
  <pre class="lang-cpp prettyprint-override"><code>void adapter_config_l2(HANDLE th,
      const std::wstring&amp; openvpn_app_path,
      const Util::TapNameGuidPair&amp; tap,
      const TunBuilderCapture&amp; pull,
      ActionList&amp; create,
      ActionList&amp; destroy,
      std::ostream&amp; os)
    {
  // Make sure the TAP adapter is set for DHCP
  {
    const Util::IPAdaptersInfo ai;
    if (!ai.is_dhcp_enabled(tap.index))
      {
        os &lt;&lt; "TAP: DHCP is disabled, attempting to enable" &lt;&lt; std::endl;
        ActionList::Ptr cmds(new ActionList());
        cmds-&gt;add(new Util::ActionEnableDHCP(tap));
        cmds-&gt;execute(os);
      }
  }
  
  // set TAP media status to CONNECTED
  Util::tap_set_media_status(th, true);
  
  // ARP
  Util::flush_arp(tap.index, os);
  
  // We must do DHCP release/renew in a background thread
  // so the foreground can forward the DHCP negotiation packets
  // over the tunnel.
  l2_thread.reset(new std::thread([this, logwrap=Log::Context::Wrapper(), tap]() {
        Log::Context logctx(logwrap);
        ::Sleep(250);
        const Util::InterfaceInfoList ii;
        {
      std::ostringstream os;
      Util::dhcp_release(ii, tap.index, os);
      OPENVPN_LOG_STRING(os.str());
        }
        ::Sleep(250);
        {
      std::ostringstream os;
      Util::dhcp_renew(ii, tap.index, os);
      OPENVPN_LOG_STRING(os.str());
        }
      }));
    }
  </code></pre>
  
  <p>What could be causing this error?</p>
  
  <p>Here's some info on my build environment:
  Windows 10, GCC 7.1.0, msys2 mingw64. im on the latest commit. my build script looks like this</p>
  
  <pre><code>#!/bin/bash
  export O3=~/Work/ovpn3
  ECHO=1 PROF=win ASIO_DIR=~/Work/asio OPENSSL_SYS=1 LZ4_SYS=1 $O3/core/scripts/build ovpncli
  </code></pre>