I am trying to run C++ on an XAMPP server using the exec() function in PHP. I am importing a C++ json library . When I run the C++ code from terminal it works perfectly, but when I run it in PHP I get no output. As soon as I add any code from the json library, I no longer get any output.
PHP:
<?php
exec("./cPlusPlus", $output);
echo $output;
?>
C++ compiled with g++ -std=c++11:
#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;
}
It seems like the problem has to do with the fact that I am using a library. Do I need to do something special in order to run libraries with the PHP exec() function?
I fixed my problem with the help of @ChristianHackl. I changed exec("./cPlusPlus", $output);
to exec("./cPlusPlus 2>&1", $output);
in order to see the thrown errors. I was then able to see the error:
libstdc++.so.6: version `GLIBCXX_3.4.14' not found
and found the solution here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.