簡體   English   中英

從PHP執行C ++時,包含的C ++庫不起作用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM