freebsd下fcgi程序例子

开发环境:freebsd or linux
开发语言:c++ 
 
代码:
#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

转载于:https://www.cnblogs.com/martianFish/archive/2013/02/27/2935978.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值