[英]Included C++ libraries are not working when executing C++ from PHP
我正在尝试使用PHP中的exec()函数在XAMPP服务器上运行C ++。 我正在导入C ++ json库 。 当我从终端运行C ++代码时,它可以正常工作,但是当我在PHP中运行它时,没有任何输出。 一旦我从json库添加任何代码,我将不再获得任何输出。
PHP:
<?php
exec("./cPlusPlus", $output);
echo $output;
?>
使用g ++ -std = c ++ 11编译的C ++:
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <json>
using namespace std;
using json = nlohmann::json;
int main(int argc, char *argsv[])
{
// If I remove this line, then I get the correct output
// If I keep this line, I get no output
json data = {"json stuff"};
cout << "This is returned to PHP.";
return 0;
}
看来问题出在我正在使用一个库上。 为了使用PHP exec()函数运行库,我是否需要做一些特殊的事情?
我在@ChristianHackl的帮助下解决了我的问题。 我更改了exec("./cPlusPlus", $output);
到exec("./cPlusPlus 2>&1", $output);
为了看到抛出的错误。 然后,我能够看到错误:
libstdc ++。so.6:找不到版本“ GLIBCXX_3.4.14”
在这里找到解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.