原因
-
使用的是Redhat5.0的系统,因为要用c++11,升级了gcc到4.8.5。要支持Linux和Win,随着项目越来越复杂,原有的一些开源库影响开发效率,所以引入boost作为基础库。
-
使用boost的process时遇到了编译错误,没有找到execvpe的定义,查了一下glibc从2.11才开始支持execvpe函数,升级glibc很危险,有可能系统直接挂掉,但是感觉2.10到2.11应该不至于太离谱,所以准备把glibc升级到2.11.1,升级中遇到各种坑,最后还是通过修改boost源码暂时解决,后续有时间再测试升级的方案。
-
环境版本
Linux kernel 2.6.18
gcc 4.8.5 (支持boost1.68的最低版本)
glibc 2.10.1
Boost 1.68.0 (支持process的版本)
修改boost
- 找到boost\process\detail\posix\executor.hpp看了一下,execvpe就是调用了一下execve,改起来太简单了。注释掉__GLIBC__ 的定义就可以了
inline int execvpe(const char* filename, char * const arg_list[], char* env[])
{
//#if defined(__GLIBC__)
// return ::execvpe(filename, arg_list, env);
//#else
//use my own implementation
std::string fn = filename;
if ((fn.find('/') == std::string::npos) && ::access(fn.c_str(), X_OK))
{
auto e = ::environ;
while ((*e != nullptr) && !boost::starts_with(*e, "PATH="))
e++;
if (e != nullptr)
{
std::vector<std::string> path;
boost::split(path, *e, boost::is_any_of(":"));
for (const std::string & pp : path)
{
auto p = pp + "/" + filename;
if (!::access(p.c_str(), X_OK))
{
fn = p;
break;
}
}
}
}
return ::execve(fn.c_str(), arg_list, env);
//#endif
}
再使用boost的process没有报错,暂时先这么处理,不知道对boost的其他模块是否有影响。