使用带有fastcgi++的会话
Using sessions with fastcgi++
我在使用fastcgi++2测试版会话时遇到问题。
这是我的代码:
#include <fastcgi++/http.hpp>
#include <fastcgi++/request.hpp>
#include <fastcgi++/manager.hpp>
#include <string>
using namespace std;
using namespace Fastcgipp::Http;
class SessionsPage : public Fastcgipp::Request<char> {
static Sessions<string> sessions;
Sessions<string>::iterator session;
bool response() {
sessions.cleanup();
out << "Content-Type: text/html;rnrn";
out << "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">" << std::endl;
out << "<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >" << std::endl;
out << " <head>" << std::endl;
out << " <title>Sessions</title>" << std::endl;
out << " <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />" << std::endl;
out << " </head>" << std::endl;
out << " <body>" << std::endl;
out << " <p>Hello World!</p>" << std::endl;
out << " </body>" << std::endl;
out << "</html>" << std::endl;
return true;
}
};
int main() {
Fastcgipp::Manager<SessionsPage> fcgi;
fcgi.handler();
}
我得到以下错误:
/tmp/ccRujo45.o: In function `SessionsPage::response()':
sessions_page.cpp:(.text._ZN12SessionsPage8responseEv[SessionsPage::response()]+0xd): undefined reference to `SessionsPage::sessions'
collect2: ld a retourné 1 code d'état d'exécution
如果我评论这一行,它会编译:
sessions.cleanup();
我正在使用本教程。
谢谢你的帮助。
static Sessions<string> sessions;
仅在类中声明;你需要为它创建一个定义。在这种情况下,我认为在你的类之后粘贴Sessions<string> SessionsPage::sessions;
是可以的,因为这个类只在一个翻译单元中使用。(如果在多个翻译单元中使用它,则必须在一个且只有一个翻译单元中定义静态变量)
相关文章:
- 为多个会话保留XPtr
- 是否可以用"iostream"包装现有的TCP/OOpenSSL会话
- 如何修复 Onnx运行时会话>运行问题?
- 为什么 KMS drmModeSetCrtc() 在 X11 会话中运行时会失败并被拒绝权限?
- 如何在带有 gdb GUI 前端的 ARM gdbserver 的 PC 上执行远程 gdb 会话?
- 宽藤会话更新无休止循环
- Windows桌面程序保存您的计算机会话 - 基于程序崩溃时的恢复会话
- 在Win7上,在默认端点上轮询音频会话有时会崩溃
- 自动测试不会显示在会话前端中。虚幻引擎
- CSActiveMQ CPP 生产者 - 一个会话可以使用多个队列吗?
- Tensorflow C++关闭会话后不释放 GPU 资源
- 在没有外部文件的情况下在应用会话之间保存变量
- 有没有办法在 C 或 C++ 中嵌入 Sh/Bash 会话?
- 与 Python 中子进程中的另一个应用程序的交互式会话
- Tensorflow C++ 代码 SessionFactory::GetFactory 如何选择使用哪个会话?直接会话
- Libssh2:在"每个线程的通道"基础上在线程之间共享 ssh 会话是否安全?
- 如何处理Qt托盘应用程序中的会话更改通知
- C/C++ 远程编译,使用 ELF 的本地调试会话(嵌入式,Cortex-M)
- Android 和 IOS 上的 Qt 会话管理
- 使用带有fastcgi++的会话