Jump to content

Problem combining c++ and .cgi

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
yuyujoke

yuyujoke

    Newbie

  • Members
  • Pip
  • 7 posts
I am attempting to write a c++ program and run it on a web server using .cgi. I've tried some examples found by googling and failed so i guess there is some other error rather than error in the actual code.
However, this is what the program i try with look like:
Code:

int main(int argc, char *argv[])
{std::cout<<"Content-type: text/html\n\n";
std::cout<<"along with some other text\n";
return(0);}

When I run this on the server I get the message
"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.", which is the same error I have received when i've, for example, tried to run a perl script with some error in it.

#2
CPD

CPD

    Learning Programmer

  • Members
  • PipPipPip
  • 57 posts
Try this since you don't use command line parameters and your code didn't include the necessary headers.

#include <iostream>


int main()

{

  std::cout<<"Content-type: text/html\n\n";

  std::cout<<"along with some other text\n";

  return(0);

}

Also, the program has to be compiled to an executable file before it can be run on the server. It's not like Perl where you can just stuff the code in there and it'll be run.

#3
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,713 posts
Are you writing your program on the server computer? If you compile it on your personal computer, leave it in debug mode, and then try to run it, it'll fail because the needed debug libraries won't be there. Make sure you compile in release mode to strip all the debug libraries out of your program.