Solved

Trying to get c++ cgi script to work in Ubuntu Apache2

Posted on 2010-09-12
5
1,063 Views
Last Modified: 2013-12-25
Hi,
I am new to Ubuntu.  My python cgi-scripts work but my c++ cgi does not.  How do I fix?
\
  In the apache error logs I get premature end of headers error.  
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log



Below is my simple cgi script.  I also did a chmod a+x and 755.  In the http.conf file I have

ScriptAlias /cgi-bin /usr/lib/cgi-bin/
<Directory /usr/lib/cgi-bin>
    Options +ExecCGI
    Order allow,deny
    Allow from all
    AddHandler cgi-script cgi o py
</Directory>


#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <string>
#include <time.h>
#include <malloc.h>

using namespace std;


int main() {

      cout << "content-type: text/html" << endl << endl;
      cout << "<html>" << endl;
      cout << "</html>" << endl;


      //cout   << "Hello! You sent " << lpszContentLength << " bytes of data which read: <br>" << endl;

      return 0;
}
0
Comment
Question by:dmontgom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 6

Expert Comment

by:DalHorinek
ID: 33657129
What is in error log?
0
 

Author Comment

by:dmontgom
ID: 33658311
Here the error log

[Sun Sep 12 18:33:09 2010] [error] (8)Exec format error: exec of '/usr/lib/cgi-bin/cpp_post_test.o' failed
[Sun Sep 12 18:33:09 2010] [error] [client 127.0.0.1] Premature end of script headers: cpp_post_test.o
0
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 33658398
Um, that's an object file, not an executable. Try to compile it like this:

g++ -o cpp_post_test cpp_post_test.cpp

This way, you will get an executable named 'cpp_post_test'. If you omit '-o <name>', you will get an executable with the default name 'a.out'.
0
 

Author Closing Comment

by:dmontgom
ID: 33658709
Good job!

Thanks
0

Featured Post

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question