【问题标题】:Visual Studio 2015: Can't find `char * * __cdecl __p__environ(void)`Visual Studio 2015:找不到`char * * __cdecl __p__environ(void)`
【发布时间】:2016-01-14 14:35:01
【问题描述】:

我正在尝试使用 VS2015 WIN64 构建 boost.process(前段时间使用 VS2010 WIN32 和 WIN64 没有任何问题)。

链接器抱怨找不到char * * __cdecl __p__environ(void)

process.obj : error LNK2019: symbole externe non résolu "char * * __cdecl __p__environ(void)" (?__p__environ@@YAPEAPEADXZ) référencé dans la fonction "public: static class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > __cdecl boost::process::self::get_environment(void)" (?get_environment@self@process@boost@@SA?AV?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@XZ)

这是导致此链接问题的代码:

#if defined(BOOST_WINDOWS_API) 
#ifdef GetEnvironmentStrings 
#undef GetEnvironmentStrings 
#endif 
    char *environ = ::GetEnvironmentStrings();
    if (!environ) 
        boost::throw_exception(boost::system::system_error(boost::system::error_code(::GetLastError(), boost::system::get_system_category()), "boost::process::self::get_environment: GetEnvironmentStrings failed")); 
    try 
    { 
        char *env = environ; 
        while (*env) 
        { 
            std::string s = env; 
            std::string::size_type pos = s.find('='); 
            e.insert(boost::process::environment::value_type(s.substr(0, pos), s.substr(pos + 1))); 
            env += s.size() + 1; 
        } 
    } 
    catch (...) 
    { 
        ::FreeEnvironmentStringsA(environ); 
        throw; 
    } 
    ::FreeEnvironmentStringsA(environ); 
#endif 

char *environ = ::GetEnvironmentStrings(); 替换为char *environ = NULL; 并不能解决问题。评论整个集团可以解决问题。

【问题讨论】:

    标签: c++ visual-c++ boost visual-studio-2015 boost-process


    【解决方案1】:

    我真倒霉……

    stdlib.h#define environ _environ(可能是 VS2015 中的新功能)...

    在 boost.process 代码(或您喜欢的任何内容)中添加 #undef environ 或将 environ 替换为 environVar 可修复编译....

    注意:不要关闭 OP,因为其他人试图编译 boost.process 可能会遇到同样的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多