• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 986
  • Last Modified:

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                            
0
aplelois
Asked:
aplelois
  • 9
  • 8
  • 2
1 Solution
 
Infinity08Commented:
use

#include <iostream>

instead of :

#include <iostream.h>
0
 
apleloisAuthor Commented:
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
0
 
Infinity08Commented:
Well, since this is a C++ program, you should compile with g++ and not gcc
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
apleloisAuthor Commented:
500 Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
0
 
apleloisAuthor Commented:
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....
0
 
Infinity08Commented:
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) ?
0
 
Infinity08Commented:
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.
0
 
apleloisAuthor Commented:
compiled fine, everything looks good... ok.. boom -> 500 Internal Server Error
0
 
AxterCommented:
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!
0
 
Infinity08Commented:
>> 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 ?
0
 
apleloisAuthor Commented:
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
0
 
Infinity08Commented:
>> Did you set the proper permissions for the file ?
Just a follow-up of this : normally you need to chmod the file to 755 ...
0
 
apleloisAuthor Commented:
yes i did this
chmod -R 755 hello.cgi
0
 
Infinity08Commented:
Why did you rename the executable to .cgi ? I'm not sure that'll work ... Try renaming it back to just hello ...

If that still doesn't help, check the log files of your HTTP server ... it should state what it was exactly that caused the 500 error message.
0
 
AxterCommented:
>>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.
0
 
apleloisAuthor Commented:
thank you guys!! I got it!
0
 
Infinity08Commented:
>> thank you guys!! I got it!
So, what was the problem ? The .cgi extension ?
0
 
apleloisAuthor Commented:
>>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
0
 
Infinity08Commented:
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 :)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 9
  • 8
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now