开发环境: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

freebsd下fcgi程序例子相关推荐

  1. 在FreeBSD下安装mysql+apache+php

    转自:[url]http://bbs.chinaunix.net/viewthread.php?tid=389832[/url] 在FreeBSD下安装mysql+apache+php ======= ...

  2. freebsd php 编译 mysql sql2005_问下:Freebsd下用php连接ms sql server

    你的位置: 问答吧 -> PHP -> 问题详情 问下:Freebsd下用php连接ms sql server 大家都怎么连接的,,,效率如何? 作者: james.liu 发布时间: 2 ...

  3. 解决Windows下Arm下Linux下Qt4程序的中文乱码问题

    解决Windows下Arm下Linux下Qt4程序的中文乱码问题 ################################################################### ...

  4. Linux下的程序调试——GDB

    无论是多么优秀的程序员,都难以保证自己在编写代码时不会出现任何错误,因此调试是软件开发过程中的一个必不可少的 组成部分.当程序完成编译之后,它很可能无法正常运行,或者会彻底崩溃,或者不能实现预期的功能 ...

  5. 操作系统(4)状态机视角下的程序执行

    操作系统(4)状态机视角下的程序执行 有限状态机(Finite-state machine, FSM) 表示有限个状态在一定的条件下发生某个动作导致从一个状态转换到另一个状态的模型. 有限状态机的要素 ...

  6. Linux下C程序的编辑,编译和运行以及调试

                                                                                                        ...

  7. cef异常处理_cefSharp在XP下使得程序崩溃记录

    前言:这是一个奇葩的问题,到现在自己还没有搞明白问题出现在哪里,但是从问题总算是解决了,希望看到此文章的大牛,如果知道问题出在什么地方,可以告知一下. [一个在XP系统下面应用程序崩溃问题] 资源: ...

  8. linux daemon步骤,编写Linux系统下Daemon程序的方法步骤

    编写Linux系统下Daemon程序的方法步骤 一.引言 Daemon程序是一直运行的服务端程序,又称为守护进程. 本文介绍了在Linux下编写Daemon程序的步骤,并给出了例子程序. 二.Daem ...

  9. linux编译freebsd,freebsd下作x86/arm linux的交叉编译器

    freebsd下作x86/arm linux的交叉编译器 2009-05-13 01:40:08来源:未知 阅读 () 以纯粹的源码编译交叉编译器,还是头一遭.以往都是利用目标主机上的头文件和库文件作 ...

  10. 客户和服务器之间响应的序列,网络编程-第五讲-TCP客户-服务器程序例子.pdf-原创力文档...

    网络编程 第五讲TCP客户-服务器程序例子 多进程并发服务器基本架构 pid_t pid; int listenfd, connfd; listenfd = Socket( ... ); /* fil ...

最新文章

  1. poj3061(二分算法)
  2. python中defaultdict()函数的介绍以及应用场景
  3. linux命令之上传文件和下载文件
  4. c# vscode 配置_使用VSCode开发C#项目
  5. CSS 实现加载动画之四-圆点旋转
  6. db2分页查询语句优化_数据量很大,分页查询很慢,该怎么优化?
  7. Oracle中分区表中表空间属性
  8. 5g存储服务器是什么项目,5G时代对服务器有什么要求?
  9. Oauth2协议详解
  10. C++奥赛一本通递推题解
  11. CentOS 7.6 vi编辑器常用命令详解
  12. LU分解算法(串行、并行)
  13. C语言apr_socket,APR分析-高级IO篇
  14. 算法日记---不同的二叉搜索树
  15. 【Scheme归纳】1 使用Edwin
  16. word文档解密方法
  17. for循环小技巧,遍历数组的时候要使用恰当
  18. [前端案例]百行代码实现炫酷时钟
  19. 树莓派存储方案_如何在树莓派上搭建私有云存储
  20. 自学无果 报班学习的每日知识点总结与回顾 0基础学前端的小伙伴可以进来看看 一起学习一起进步(三)

热门文章

  1. 移动、复制、新增工作表
  2. 解决jenkins插件列表为空的问题
  3. 《算法竞赛入门经典》习题及反思 -2
  4. 【Java中的网络编程】
  5. Visual Sourcesafe Internet使用备忘
  6. asp.net生成随机数或字母验证码代码
  7. Advanced Object Creation(JS,翻译MSDN文章)
  8. Ubuntu 16.04中的Dock的应用顺序调整
  9. 双11秒查包裹,菜鸟携快递公司推出云客服功能
  10. BST B-树 B+树 B*树简介