1

I can't even get a simple test program working with CGI. Here's my code. It works when I run it in the console, but gives the error when I try to run from Apache:

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

int main() {
    printf("Content-type: text/html\n\n");
    printf("TEST");
    return 0;
}

MakeFile:

build: source/main.cpp
    C:/MinGW/bin/g++.exe -o build/e2.exe source/main.cpp

Error:

[Thu Mar 22 19:14:23 2012] [error] [client 127.0.0.1] Premature end of script headers: e2.exe

Run in command prompt:

C:\Users\Stephen>C:\wamp\www\e2.exe
Content-type: text/html

TEST

Any help would be greatly appreciated! Thanks!

Solved: Makefile:

build: source/main.cpp
    C:/MinGW/bin/gcc.exe -o build/e2.exe source/main.cpp
Stephen Smith
  • 485
  • 1
  • 6
  • 14
  • 4
    HTTP line endings are `\r\n`. – Kerrek SB Mar 22 '12 at 23:21
  • @KerrekSB: I would like to know the difference. Any further reading on it? – Straseus Mar 22 '12 at 23:25
  • No further than the end of the line :-) But seriously, that's just part of the protocol specification. You can read the RFC if you dare. – Kerrek SB Mar 22 '12 at 23:28
  • Why read RFCs when some cool person can summarize it for you: http://stackoverflow.com/a/5757349/1210546 – Straseus Mar 22 '12 at 23:30
  • Doesn't MinGW use Windows' style line endings? Since the OP is working on Windows, the \n should be translated to CRLF. I've checked with dev-c++ (don't remember which is the C++ compiler behind), and using printf("abc\n\n"); gives me two CRLF, while printf("abc%c%c",13,13); gives me two CR only. – huelbois Mar 23 '12 at 00:06

1 Answers1

1

Solved: Makefile:

build: source/main.cpp
    C:/MinGW/bin/gcc.exe -o build/e2.exe source/main.cpp

GCC not G++

Stephen Smith
  • 485
  • 1
  • 6
  • 14