Click here to Skip to main content
16,020,673 members
Please Sign up or sign in to vote.
2.67/5 (3 votes)
See more:
1. Issue:

I have installed Apache (see the referenced phpinfo output for more details) and I am trying to demonstrate C++ scripting with a "Hello Word" example. This is mostly a setup issue.

Once 64-bit Apache is installed, what else needs to be done to get C++ scripting to work? Is that done in the php framework?

-A small program for instance could be created as a cgi script that would just run the compiler and run the output generated as an interpreter of sorts.

-But with PHP, it is possible to just load the .dll; why not also with C++?

I like C++ because of the way that it is possible to organize the code;
-I like the hierarchical structure better; it seems more flexible
-Also, it is easier to translate between paper documents and C++ code

2. Probing
-I tried to find references to the issue; I remember reading material before that seemed to suggest that it might be possible directly.
-From GCI, it seems that it is possible to compile the programs as modules that can load into Apache directly

3. Analysis
-I am not finding the direct approach for a C++ interpreter that would work like PHP; however the indirect approach of compile and run might be possible
-The workaround would be to build the CGI interface in C++ and compile it and then run it.

4. Isolation
-I am trying to see if Cygwin would work with its language package following:

Cygwin - Part Two - Installing GCC[1]

and also following

Cygwin - Part Three - Testing the GCC C++ Compiler[2]

and most importantly "Introduction to C++ CGI":

Introduction to C++ CGI | Guy Rutenberg[4]

See the references for more detail (and additional perhaps related information).

4. Resolution

No resolution yet; Is there a C++ interpreter available? Or does the software need to be written in C++ again (I guess to use the Cygwin compiler from windows to take a given code, save it, and then compile it and run it, or the equivalent under Windows or other operating systems.)


6.1 References - attempted research to resolve the issue


C#
40. http://localhost/wordpress/wp-admin/setup-config.php
http://localhost/wordpress/wp-admin/setup-config.php

41. phpinfo()
http://localhost/test.php

42. test.php -Google

43. PHP: Your first PHP-enabled page - Manual
http://php.net/manual/en/tutorial.firstpage.php

47. 2016-02-03T10:46:34+00:00-phpinfo().pdf
http://www.gonorthwork.com/view/2016-02-03T10:46:34+00:00-phpinfo().pdf

48. c++ scripting with php -Google

49. execute c++ program with php script - Stack Overflow
http://stackoverflow.com/questions/4279003/execute-c-program-with-php-script

50. Run C++ script in PHP - Stack Overflow
http://stackoverflow.com/questions/11789095/run-c-script-in-php

51. Calling a PHP script from a C++ Program - Stack Overflow
http://stackoverflow.com/questions/9470448/calling-a-php-script-from-a-c-program

52. interpreted c++ running under php - Google
https://www.google.co.il/search?q=interpreted+c%2B%2B+running+under+php&ie=utf-8&oe=utf-8&gws_rd=cr&ei=3t6xVpydD4PcUe2drjg

53. c++ to php compiler - Google

54. c++ to php compiler - Google

55. Compile and Execute C++ Online
http://www.tutorialspoint.com/compile_cpp11_online.php

56. writing a script interpreting module for Apache -Google

57. Apache Tutorial: Dynamic Content with CGI - Apache HTTP Server Version 2.2
https://httpd.apache.org/docs/2.2/howto/cgi.html

58. Writing Apache Modules with Perl and C: The Apache API and Mod_perl - Lincoln Stein, Doug MacEachern - Google ספרים
https://books.google.co.il/books?id=qyzTI_eAeHUC&pg=PA5&lpg=PA5&dq=writing+a+script+interpreting+module+for+Apache&source=bl&ots=16jFAAjtSd&sig=ePrYEm6tT2Pe9UNxh_ixGX9wkP4&hl=iw&sa=X&ved=0ahUKEwimna22utvKAhVDJQ8KHdR7CioQ6AEIPTAD#v=onepage&q=writing%20a%20script%20interpreting%20module%20for%20Apache&f=false

59. CgiScripts - Python Wiki
https://wiki.python.org/moin/CgiScripts

60. CGI -Google
https://www.google.co.il/search?q=CGI&ie=utf-8&oe=utf-8&gws_rd=cr&ei=PuCxVtWcFsG4ygOHxrSgCA

61. Apache Tutorial: Dynamic Content with CGI - Apache HTTP Server Version 2.2
https://httpd.apache.org/docs/2.2/howto/cgi.html

62. Writing CGI programs for Windows 7.1 -Google

63. CGI Programming With Apache and Perl on Windows XP
http://www.cgi101.com/book/connect/winxp.html

64. writing a c++ windows cgi program for apache -Google

65. The Megalomaniac Bore: C++ based CGI with Apache on Win32 & Linux
http://megalomaniacbore.blogspot.co.il/2011/07/c-based-cgi-with-apache-on-win32-linux.html

66. How to config apache for C++ CGI scripts? - Stack Overflow
http://stackoverflow.com/questions/9753689/how-to-config-apache-for-c-cgi-scripts

67. A Short Guide to writing server-side CGI programs in C++ - Wikiid
http://www.sjbaker.org/wiki/index.php?title=A_Short_Guide_to_writing_server-side_CGI_programs_in_C%2B%2B

68. C++ Web Programming
http://www.tutorialspoint.com/cplusplus/cpp_web_programming.htm

69. HOW-TO Write a CGI Program in C/C++
http://www.purplepixie.org/cgi/howto.php

70. Introduction to C++ CGI | Guy Rutenberg
https://www.guyrutenberg.com/2007/08/10/introduction-to-c-cgi/

71. Code::Blocks download | SourceForge.net
http://sourceforge.net/projects/codeblocks/?source=typ_redirect

72. c++ compiler for code blocks -Google

73. Installing a supported compiler - CodeBlocks
http://wiki.codeblocks.org/index.php/Installing_a_supported_compiler#Microsoft_Visual_C.2B.2B

74. Borlad C++ - חיפוש ב-Google
https://www.google.co.il/search?q=Borlad+C%2B%2B&ie=utf-8&oe=utf-8&gws_rd=cr&ei=d-SxVqbMOIXVO8aYgrgO

75. Download Borland C++ Compiler For Free - The Crazy Programmer
http://www.thecrazyprogrammer.com/2015/01/download-borland-c-compiler-for-free.html

76. GCC Compiler: Download Code::Blocks 12.11 a Free C/C++ IDE - The Crazy Programmer
http://www.thecrazyprogrammer.com/2013/06/gcc-compiler-download-codeblocks-1211.html

77. download GCC for windows -Google

78. Mingw-w64 - GCC for Windows 64 & 32 bits [mingw-w64]
http://mingw-w64.org/doku.php

79. Win-builds [mingw-w64]
http://mingw-w64.org/doku.php/download/win-builds

80. Intel C/C++ Compiler for Wndows 7 - חיפוש ב-Google
https://www.google.co.il/search?q=Intel+C/C%2B%2B+Compiler+for+Wndows+7&ie=utf-8&oe=utf-8&gws_rd=cr&ei=e-WxVuvmN8fcO9eBjYAE

81. Installing a supported compiler - CodeBlocks
http://wiki.codeblocks.org/index.php/Installing_a_supported_compiler

82. Cygwin
http://www.cygwin.org/

84. Intel C++ compiler in windows 7 64 bits
https://software.intel.com/en-us/forums/intel-c-compiler/topic/279145

85. Intel C++ Compiler 11.1.067 (free) - Download latest version in English on phpnuke
https://2ra5-downloads.phpnuke.org/en/c62877/intel-c-compiler

87. how to use cygwin C++ compiler -Google

88. Cygwin - Part Three - Testing the GCC C++ Compiler
http://www2.warwick.ac.uk/fac/sci/moac/people/students/peter_c**k/cygwin/part3/

90. Cygwin - Part Two - Installing GCC
http://www2.warwick.ac.uk/fac/sci/moac/people/students/peter_c**k/cygwin/part2/

91. libusb-win32 download | SourceForge.net
http://sourceforge.net/projects/libusb-win32/?source=typ_redirect


6.2 References part 2:

From Send Tab URLs (31 links)


1. How can I demonstrate C++ scripting via the web with Apache and Windows 7.1 64-bit? - CodeProject
http://www.codeproject.com/Questions/1076387/How-can-I-demonstrate-Cplusplus-scripting-via-the

2. Cygwin - Part Three - Testing the GCC C++ Compiler
http://www2.warwick.ac.uk/fac/sci/moac/people/students/peter_c**k/cygwin/part3/

3. Introduction to C++ CGI | Guy Rutenberg
https://www.guyrutenberg.com/2007/08/10/introduction-to-c-cgi/

4. Introduction to C++ CGI – Processing Forms | Guy Rutenberg
http://www.guyrutenberg.com/2007/09/07/introduction-to-c-cgi-processing-forms/

5. Introduction to C++ CGI | Guy Rutenberg
http://www.guyrutenberg.com/2007/08/10/introduction-to-c-cgi/

6. 404 Not Found
http://localhost/helloworld.cpp

7. c++ CGI - חיפוש ב-Google
https://www.google.co.il/search?q=c%2B%2B+CGI&ie=utf-8&oe=utf-8&gws_rd=cr&ei=sAWyVoqLGMSYsAH4qpK4Aw

8. C++ Web Programming
http://www.tutorialspoint.com/cplusplus/cpp_web_programming.htm

9. 500 Internal Server Error
http://localhost/cgi-bin/cplusplus.cgi

10. Hello World - First CGI Program
http://www.tutorialspoint.com/cgi-bin/cplusplus.cgi

11. Index of ftp://ftp.gnu.org/gnu/cgicc/
ftp://ftp.gnu.org/gnu/cgicc/

12. ftp://ftp.gnu.org/gnu/cgicc/README
ftp://ftp.gnu.org/gnu/cgicc/README

13. 404 Not Found
http://localhost/cplusplus

14. apache server log - חיפוש ב-Google
https://www.google.co.il/search?q=apache+server+log&ie=utf-8&oe=utf-8&gws_rd=cr&ei=wAyyVsT_CMXAOZ69hrAL

15. Log Files - Apache HTTP Server
https://httpd.apache.org/docs/1.3/logs.html

16. apache error End of script output before headers - חיפוש ב-Google
https://www.google.co.il/search?q=apache+error+End+of+script+output+before+headers&ie=utf-8&oe=utf-8&gws_rd=cr&ei=KA2yVpPgN8OSPqqxssAM

17. perl - "End of script output before headers" error in Apache - Stack Overflow
http://stackoverflow.com/questions/22307610/end-of-script-output-before-headers-error-in-apache

18. 500 Internal Server Error
http://localhost/cgi-bin/printenv.pl

19. .pl #! cgi path to perl windows - חיפוש ב-Google
https://www.google.co.il/search?q=cgi+path+to+perl&ie=utf-8&oe=utf-8&gws_rd=cr&ei=8Q2yVoPyO8LCPO2rl-AC#q=.pl+%23!+cgi+path+to+perl+windows

20. Configuring the Apache Web Server to Run Perl Programs on Windows
http://editrocket.com/articles/perl_apache_windows.html

21. Setting up Perl/CGI with Windows
http://www.perlmonks.org/?node_id=44536

22. How to install Perl on Windows | ricocheting.com
http://www.ricocheting.com/how-to-install-on-windows/perl

23. How can I set Perl's inclusion path for modules for a CGI script? - Stack Overflow
http://stackoverflow.com/questions/355267/how-can-i-set-perls-inclusion-path-for-modules-for-a-cgi-script

24. how to restart the apache server httpd - חיפוש ב-Google
https://www.google.co.il/search?q=how+to+restart+the+apache+server+httpd&ie=utf-8&oe=utf-8&gws_rd=cr&ei=2xCyVoWlGoaAPK6tkdAP

25. Start / Stop and Restart Apache 2 Web Server Command
http://www.cyberciti.biz/faq/star-stop-restart-apache2-webserver/

26. Problem loading page
http://localhost/

27. perl for windows 7 64 bit apache - חיפוש ב-Google
https://www.google.co.il/search?q=perl+for+windows+7+64+bit+apache&ie=utf-8&oe=utf-8&gws_rd=cr&ei=TxKyVvnYCYOAU5LotdgP#q=perl+for+windows+7+64+bit+apache&start=10

28. How to install Perl on Windows | ricocheting.com
http://www.ricocheting.com/how-to-install-on-windows/perl

29. Thank you for downloading ActivePerl | ActiveState Software
http://www.activestate.com/activeperl/downloads/thank-you?dl=http://downloads.activestate.com/ActivePerl/releases/5.22.1.2201/ActivePerl-5.22.1.2201-MSWin32-x64-299574.msi

30. CGI #!/path/to/perl windows example - חיפוש ב-Google
https://www.google.co.il/search?q=%23!/path/to/perl+example&ie=utf-8&oe=utf-8&gws_rd=cr&ei=sxOyVpWIMozSUZmmhNgJ#q=CGI+%23!%2Fpath%2Fto%2Fperl+windows+example

31. apache - How to run perl files over xampp in windows? - Stack Overflow
http://stackoverflow.com/questions/7860380/how-to-run-perl-files-over-xampp-in-windows


6.3 References Part 3

C#
5. c++ cgi scripting - Google Search

6. cgicc: A Tutorial Example
http://www.gnu.org/software/cgicc/doc/cgicc_tutorial.html

7. cgicc:
http://www.gnu.org/software/cgicc/doc/index.html

8. cgicc for windows 7 - Google Search

9. gnu cgi (cgicc) does not compile with gcc on Windows using MinGW/Cygwin - Stack Overflow
http://stackoverflow.com/questions/4866451/gnu-cgi-cgicc-does-not-compile-with-gcc-on-windows-using-mingw-cygwin

10. Cgicc - Free Software Directory
https://directory.fsf.org/wiki/Cgicc





Update #1:

I found a sample file printenv.pl and I modified that slightly (changing the header), after checking the error logs for Apache. The new code is:

PERL
#!C:/Perl64/bin/perl.exe
# To permit this cgi, replace # on the first line above with the
# appropriate #!/path/to/perl shebang, and on Unix / Linux also
# set this script executable with chmod 755.
#
# ***** !!! WARNING !!! *****
# This script echoes the server environment variables and therefore
# leaks information - so NEVER use it in a live server environment!
# It is provided only for testing purpose.
# Also note that it is subject to cross site scripting attacks on
# MS IE and any other browser which fails to honor RFC2616.
##
## printenv -- demo CGI program which just prints its environment
##
use strict;
use warnings;
print "Content-type: text/plain; charset=iso-8859-1\n\n";
foreach my $var (sort(keys(%ENV))) {
my $val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";
}
Posted
Updated 8-Feb-16 21:18pm
v6
Comments
enhzflep 3-Feb-16 8:14am    
Ouch! Someone/thing have complicated the issue for you needlessly. It can be as simple as outputting to stdout for output (using printf/cout etc). If you're running XAMPP under windows, you build the program, drop the .exe into the cgi-bin folder of the appache installation and hit it with the browser.

Here's a minimal example:
cgiTest.c

#include <stdio.h>
#include <stdlib.h>

int main()
{
printf("Content-Type:text;charset=iso-8859-1\r\n\r\n");
printf("Hello webWorld from .C program");
return(0);
}


I just hit it with the url "localhost/cgi-bin/cgiTest.exe"

The topic is of course, far broader and there are many caveats and gotchas that I wont cover. I do recall there being a library called fastcgi or something like that, which will allow you to handle GET/POST requests etc. There's naturally going to be something that allows you to send back a gzipped output etc, etc.

After playing with it for a few days a couple of years back, I was able to take a photo using the web-cam and send the image to the browser. It's relatively straight forward - dealing with the camera was far harder than any of the stuff that made it web-friendly, or "cgi-able"
StephenJElliott 9-Feb-16 3:52am    
Thank you for the update.. I ended up not using XAMPP under windows, just Apache, PHP and MySQL; finally it seems to work. The important thing is to have a version with the .exe extension to see if the .exe actually runs! Of course in the cgi-bin directory for the Apache web server, the .exe extension is changed to .cgi for the web server to be able to present the output. I had wanted to use C++ as a scripting language so that I could program certain segments later, but in the meanwhile php can be used directly within WordPress for instance, which relies on a database (so the coding becomes a document issue instead of a presentation issue with the document being in the database).
[no name] 3-Feb-16 11:11am    
Since C++ is not a scripting language, you need to capture the complete source, and then compile and link it into an executable module.
StephenJElliott 4-Feb-16 3:56am    
I am able to get perl to execute (more details in the main text). So the question is why is the main code not executing. I wonder if I write a perl script that just has the first line with the index to the actual code that I want to run, if that would work.
[no name] 4-Feb-16 4:03am    
Sorry, but I am not sure I understand what problem you are trying to solve. And having just re-read your main question, am even more confused.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900