在mingw64-变量下的windows中编译openvpn3的错误未在范围中声明

时间:2017-07-18 21:11:20

标签: c++ mingw openvpn

尝试在mingw64下的windows中编译openvpn3(https://github.com/OpenVPN/openvpn3)时出现此错误

$ ./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&, const openvpn::TunWin::Util::TapNameGuidPair&, const openvpn::TunBuilderCapture&, openvpn::ActionList&, openvpn::ActionList&, std::ostream&)':
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: '<typeprefixerror>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: '<typeprefixerror>tap' declared here
  l2_thread.reset(new std::thread([this, logwrap=Log::Context::Wrapper(), tap]() {
                                                                      ^~~

我查看了导致错误的头文件,并在函数参数中定义了tap

void adapter_config_l2(HANDLE th,
    const std::wstring& openvpn_app_path,
    const Util::TapNameGuidPair& tap,
    const TunBuilderCapture& pull,
    ActionList& create,
    ActionList& destroy,
    std::ostream& os)
  {
// Make sure the TAP adapter is set for DHCP
{
  const Util::IPAdaptersInfo ai;
  if (!ai.is_dhcp_enabled(tap.index))
    {
      os << "TAP: DHCP is disabled, attempting to enable" << std::endl;
      ActionList::Ptr cmds(new ActionList());
      cmds->add(new Util::ActionEnableDHCP(tap));
      cmds->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());
      }
    }));
  }

可能导致此错误的原因是什么?

这里有关于我的构建环境的一些信息: Windows 10,GCC 7.1.0,msys2 mingw64。即时通讯最新提交。我的构建脚本看起来像这样

#!/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

1 个答案:

答案 0 :(得分:0)

我通过改变

中线程的捕获顺序来修复它
l2_thread.reset(new std::thread([this, logwrap=Log::Context::Wrapper(), tap](){

l2_thread.reset(new std::thread([this, tap, logwrap=Log::Context::Wrapper()](){

我真的不明白为什么要解决这个问题