【发布时间】:2013-10-22 20:08:49
【问题描述】:
我有一些现有代码,我正在尝试使用来自llvm.org 的 clang 3.3 和 libc++ 进行编译。检索另一个命令的结果的简单步骤。看来 std::filebuf 不再提供 FILE* 构造函数,我试图替换代码的所有想法都未能打开命令,即 fb.is_open() 总是返回 false。
据我所知,我必须使用 fb.open(cppcommand.c_str(), std::ios::in); 之类的东西,而不是 popen。
代码的基本部分是:-
std::string cppcommand = "/usr/bin/cpp -xc -nostdinc test.c";
FILE *cpppipe = popen (cppcommand.c_str(), "r");
std::filebuf fb (cpppipe);
if (! cpppipe || ! fb.is_open()) {
std::cerr << "Could not run '" << cppcommand.c_str() << "'\n";
return false;
} else {
std::istream in (&fb);
std::ostringstream ss;
ss << in.rdbuf();
result = ss.str();
}
如何使用 libc++ 运行它?
代码来自OpenShadingLanguage,在从基本安装中删除 gcc 和 libstdc++ 后,我正试图让它在包含 clang 3.3 和 libc++ 的 FreeBSD 10.0 Beta1 下编译。
如果手动粘贴到终端,正在使用的 cppcommand 字符串运行不会出错。
【问题讨论】: