Link to home
Start Free TrialLog in
Avatar of aplelois
aplelois

asked on

CGI

hello,
why is this when I try to compile my app..

#include <iostream.h>
using namespace std;

int main()
{
      cout << "content-type: text/html" << endl << endl;

      cout << "<HTML><BODY>" << endl;
      cout << "<H1> Hello, World! </H1>" << endl;
      cout << "</BODY></HTML>" << endl;

      return 0;
}

------------------------


/home/virtual/site.net/var/www/cgi-bin)] $ gcc -o hello a.cpp
In file included from /usr/include/c++/3.3.2/backward/iostream.h:31,
                 from a.cpp:2:
/usr/include/c++/3.3.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
/tmp/ccPB2kXj.o(.text+0x28): In function `main':
: undefined reference to `std::cout'
/tmp/ccPB2kXj.o(.text+0x2d): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
/tmp/ccPB2kXj.o(.text+0x3d): In function `main':
: undefined reference to `std::cout'
/tmp/ccPB2kXj.o(.text+0x42): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
/tmp/ccPB2kXj.o(.text+0x52): In function `main':
: undefined reference to `std::cout'
/tmp/ccPB2kXj.o(.text+0x57): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
/tmp/ccPB2kXj.o(.text+0x67): In function `main':
: undefined reference to `std::cout'
/tmp/ccPB2kXj.o(.text+0x6c): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
/tmp/ccPB2kXj.o(.text+0x7c): In function `main':
: undefined reference to `std::cout'
/tmp/ccPB2kXj.o(.text+0x81): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
/tmp/ccPB2kXj.o(.text+0x9c): In function `main':
: undefined reference to `std::cout'
/tmp/ccPB2kXj.o(.text+0xa1): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
/tmp/ccPB2kXj.o(.text+0xb1): In function `main':
: undefined reference to `std::cout'
/tmp/ccPB2kXj.o(.text+0xb6): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
/tmp/ccPB2kXj.o(.text+0xf8): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccPB2kXj.o(.text+0x127): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccPB2kXj.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status                            
Avatar of Infinity08
Infinity08
Flag of Belgium image

use

#include <iostream>

instead of :

#include <iostream.h>
Avatar of aplelois
aplelois

ASKER

gcc -o hello a.cpp
/tmp/cc8xKCU7.o(.text+0x14): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/tmp/cc8xKCU7.o(.text+0x1c): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/tmp/cc8xKCU7.o(.text+0x29): In function `main':
: undefined reference to `std::cout'
/tmp/cc8xKCU7.o(.text+0x2e): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
/tmp/cc8xKCU7.o(.text+0x37): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/cc8xKCU7.o(.text+0x40): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/cc8xKCU7.o(.text+0x4b): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/tmp/cc8xKCU7.o(.text+0x58): In function `main':
: undefined reference to `std::cout'
/tmp/cc8xKCU7.o(.text+0x5d): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
/tmp/cc8xKCU7.o(.text+0x66): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/cc8xKCU7.o(.text+0x71): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/tmp/cc8xKCU7.o(.text+0x7e): In function `main':
: undefined reference to `std::cout'
/tmp/cc8xKCU7.o(.text+0x83): In function `main':
: undefined reference to `std::cout'
/tmp/cc8xKCU7.o(.text+0xa9): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
/tmp/cc8xKCU7.o(.text+0xb2): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/cc8xKCU7.o(.text+0xde): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/cc8xKCU7.o(.text+0x10d): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/cc8xKCU7.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
Well, since this is a C++ program, you should compile with g++ and not gcc
500 Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
i have been trying for the last 5 hour to run a CGI C++ file in my server..
I downloaded a file from a website that came copiled already in C and
works fine but I can't get my own samples to work....
What format did the one you downloaded came in ?
Is the folder you placed this in the same ?
Is the server still up ... ie. can you still run the one you downloaded ?
Can you run the executable manually (on the server : ./hello) ?
Try to compile this one with gcc (it's a C program) :

#include <stdio.h>

int main() {
     printf("content-type: text/html\n\n");
     printf("Hello world");
     return 0;
}

And see if you can run it as CGI from a browser.
compiled fine, everything looks good... ok.. boom -> 500 Internal Server Error
Hi aplelois,
> #include <iostream.h>

FYI:
The above header is not part of the C++ standard, and therefore not portable.
It should not be used.
Use the following instead:
#include <iostream>

Mixing the non-standard iostream.h header with using namespace std, can cause problems compiling when other standard headers are included.


Cheers!
>> compiled fine, everything looks good... ok.. boom -> 500 Internal Server Error
Did you set the proper permissions for the file ? Check your HTTP server's manual to know which to set for CGI.

Are the settings for CGI all ok for the server ?

How about the 4 questions I asked earlier ?
sorry Axter but Infinity08 already said that!!!

--Infinity08--
>>What format did the one you downloaded came in ?
here is the download file turbotraffictrader.com/download/ttt-c-version2-Linux.tgz

>>Is the folder you placed this in the same ?
yes, its in /cgi-bin/

>>Is the server still up ... ie. can you still run the one you downloaded ?
yes, its up

>>Can you run the executable manually (on the server : ./hello)
yes I can
>> Did you set the proper permissions for the file ?
Just a follow-up of this : normally you need to chmod the file to 755 ...
yes i did this
chmod -R 755 hello.cgi
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>sorry Axter but Infinity08 already said that!!!

I just notice that.

When I first scrolled through your question, your first post and second post looked like on continuous post, and I din't see Infinity08's comment.
thank you guys!! I got it!
>> thank you guys!! I got it!
So, what was the problem ? The .cgi extension ?
>>check logs
i was compiling the files as root so when thats why i was getting the 500 error
so what im doing now is

Upload source code compile it...
download the compiled file -> then Upload it again!!
then make 755 permision
heh :)

btw : it's never a good idea to compile as root !!! Let alone anything else. Root should be kept for system management operations only !! And even then only when absolutely needed ... it prevents some less pleasant surprises :)