3

i have a small problem, i have a c++ program, but PHP is not showing output, only "blank". I made a small program to test, when I use "printf" and "gcc" to compile, it works fine, but when I compile the same progran using "g++" it fails to show the content in the php page. Any ideas? I can't use "gcc" because my project is in c++

I'm using this version of gcc/g++

g++ (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)

EDIT: I simplified the problem so you can understand what is going on here, thanks for your help. Now i get a missing library error.

I compiled the files using the followings commands:

gcc -o prueba1 prueba.c
g++ -o prueba2 prueba.cpp

So "prueba1" is the one compiled with GCC and "prueba2" is the one compiled with G++

Here is the file test.php

<?php
      echo "Executing file compiled with GCC <br />"; 
      echo shell_exec("./prueba1");
      echo "<br />";
      echo "Executing file compiled with G++ <br />";
      echo shell_exec("./prueba2 2>&1");
?>

I get this on the browser:

Executing file compiled with GCC
Hello World (GCC) 
Executing file compiled with G++
./prueba2: /opt/lampp/lib/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/libstdc++.so.6)

Here is the prueba.c file:

#include <stdio.h>

int main(int argc, char *argsv[]){

printf("Hello World (GCC)\n");

return(0);

}

Here is the prueba.cpp file:

#include <iostream>

using namespace std;

int main(int argc, char *argsv[]){

cout << "Hello World (G++)" << endl;

return(0);

}
38
  • 12
    This question makes no sense. You have some C++ source code, which you compile with GCC? What does this have to with PHP? Commented Apr 3, 2011 at 17:58
  • 3
    You need to provide us with code. Commented Apr 3, 2011 at 17:59
  • 1
    please show the piece of PHP you use to call your external program. Commented Apr 3, 2011 at 18:02
  • 1
    what happens when you call the c++ program directly from the command line? where is the source? what are the compiler warnings you're getting? Commented Apr 3, 2011 at 18:30
  • 1
    @Pace Your problem simply cannot be reproduced. Copying the above files and compiling them with gcc and g++ (using the same version as you) yields exactly the expected output. Try it yourself in a fresh directory. I doubt you’ll be able to reproduce the problem yourself. Commented Apr 3, 2011 at 19:29

1 Answer 1

2

Rename the /opt/lampp/lib/libgcc_s.so.1 to /opt/lampp/lib/libgcc_s.so.1.backup, it seems C++ was trying to access this one instead the one that linux does when running from command line, thanks for the help guys

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.