PDA

View Full Version : Compiling c++ code possible?



choward
08-29-2008, 07:39 PM
Hi. I own a domain at bluehost. I typically do all the scripting for the site in Perl. However, I recently started learning C++. When I noticed g++ was installed on the server for my site, I was curious if I could compile code on it. I tried it with some really simple code but only got a host of non-sensical compiler errors.

I asked someone in Bluehost chat about it and he said the they didn't support that. But he also said I should post something in the forum and see if anyone else had success trying something like this.

I was mainly just playing around, being interested in the idea of making CGI-style programs in C++ instead of Perl. I suppose I could try uploading binaries, but I would have to make a virtual machine or something first, because I think my site server is running Redhat-64bit, while I only use 32bit at home. (I tried uploading a binary compiled on a 32 bit machine, but it wouldn't run on the site server -- floating point error.)

Eriksrocks
08-31-2008, 05:57 PM
What are the compiler errors? That's basically the only way you can know what's going wrong. :)

You could compile C++ programs from a PHP script and then print the output of the command using something like:



<?php
$output = shell_exec('g++ prog.cpp -o prog');
echo "<pre>$output</pre>";
?>

Hope that helps. :)

choward
09-27-2008, 07:46 PM
I forgot about this post for several weeks and then came back to it. I thought I'd mention (for the benefit of the forum) that the problem seems to be solved. I compiled some C++ code on my Bluehost server today, and had no problems.

I think the problem I had earlier was not due to any restrictions from bluehost -- I just think that I wasn't familiar enough with g++ at the time.

This seemed to work just fine for a simple cgi-application:

# g++ main.cpp -c
# g++ main.o -o test.cgi

Then I just moved test.cgi into my cgi-bin.