freebsd下fcgi程序例子
2013-02-27 22:58 好动的树懒 阅读(1804) 评论(0) 编辑 收藏 举报#include <stdlib.h> #include <stdio.h> #ifdef _WIN32 #include <process.h> #else #include <unistd.h> extern char ** environ; #endif #include <fcgio.h> #include <fcgi_config.h> // HAVE_IOSTREAM_WITHASSIGN_STREAMBUF #include <fcgi_stdio.h> int main(void) { int count = 0; while(FCGI_Accept() >= 0) { printf("Content-type: text/html\r\n"); printf("\r\n"); printf("Hello world!<br>\r\n"); printf("Request number %d.", count++); } return 0; }
测试:http://127.0.0.1/lovely.fcgi
输出:Hello world!
Request number 0.
刷新:
Hello world!
Request number 1.
遇到问题:
1、undefined reference to FCGI_printf
2、undefined reference to `std::ios_base::Init::Init()
错误原因分析:参见笔记其他文章。
root@mypc % cc -o lovely.fcgi fcgi.cpp -I /usr/local/include -L /usr/local/lib/
/var/tmp//ccmFcKvo.o: In function `std::__verify_grouping(char const*, unsigned int, std::string const&)':
fcgi.cpp:(.text+0x1e): undefined reference to `std::string::size() const'
fcgi.cpp:(.text+0x69): undefined reference to `std::string::operator[](unsigned int) const'
fcgi.cpp:(.text+0xa7): undefined reference to `std::string::operator[](unsigned int) const'
fcgi.cpp:(.text+0xef): undefined reference to `std::string::operator[](unsigned int) const'
/var/tmp//ccmFcKvo.o: In function `__static_initialization_and_destruction_0(int, int)':
fcgi.cpp:(.text+0x13d): undefined reference to `std::ios_base::Init::Init()'
/var/tmp//ccmFcKvo.o: In function `__tcf_0':
fcgi.cpp:(.text+0x18e): undefined reference to `std::ios_base::Init::~Init()'
/var/tmp//ccmFcKvo.o: In function `main':
fcgi.cpp:(.text+0x1c2): undefined reference to `FCGI_printf'
fcgi.cpp:(.text+0x1ce): undefined reference to `FCGI_printf'
fcgi.cpp:(.text+0x1da): undefined reference to `FCGI_printf'
fcgi.cpp:(.text+0x1f1): undefined reference to `FCGI_printf'
fcgi.cpp:(.text+0x1f6): undefined reference to `FCGI_Accept'
/var/tmp//ccmFcKvo.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
root@mypc % cc -I /usr/local/include -L /usr/local/lib/ -lfcgi fcgi.cpp
/var/tmp//ccfGPFwl.o: In function `std::__verify_grouping(char const*, unsigned int, std::string const&)':
fcgi.cpp:(.text+0x1e): undefined reference to `std::string::size() const'
fcgi.cpp:(.text+0x69): undefined reference to `std::string::operator[](unsigned int) const'
fcgi.cpp:(.text+0xa7): undefined reference to `std::string::operator[](unsigned int) const'
fcgi.cpp:(.text+0xef): undefined reference to `std::string::operator[](unsigned int) const'
/var/tmp//ccfGPFwl.o: In function `__static_initialization_and_destruction_0(int, int)':
fcgi.cpp:(.text+0x13d): undefined reference to `std::ios_base::Init::Init()'
/var/tmp//ccfGPFwl.o: In function `__tcf_0':
fcgi.cpp:(.text+0x18e): undefined reference to `std::ios_base::Init::~Init()'
/var/tmp//ccfGPFwl.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
root@mypc % gcc -I /usr/local/include -L /usr/local/lib/ -lfcgi fcgi.cpp
/var/tmp//cc0Anyuk.o: In function `std::__verify_grouping(char const*, unsigned int, std::string const&)':
fcgi.cpp:(.text+0x1e): undefined reference to `std::string::size() const'
fcgi.cpp:(.text+0x69): undefined reference to `std::string::operator[](unsigned int) const'
fcgi.cpp:(.text+0xa7): undefined reference to `std::string::operator[](unsigned int) const'
fcgi.cpp:(.text+0xef): undefined reference to `std::string::operator[](unsigned int) const'
/var/tmp//cc0Anyuk.o: In function `__static_initialization_and_destruction_0(int, int)':
fcgi.cpp:(.text+0x13d): undefined reference to `std::ios_base::Init::Init()'
/var/tmp//cc0Anyuk.o: In function `__tcf_0':
fcgi.cpp:(.text+0x18e): undefined reference to `std::ios_base::Init::~Init()'
/var/tmp//cc0Anyuk.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
正确命令为:gcc -I /usr/local/include -L /usr/local/lib/ -lfcgi -lstdc++ -o lovely.fcgi fcgi.cpp