Solved

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

Posted on 2010-09-12
5
1,055 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 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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 …

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now