Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-09-12
5
Medium Priority
?
1,071 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
  • 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 1000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
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 …
Suggested Courses

885 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