c++ - 使用带有 fastcgi++ 的 session

标签 c++ fastcgi++

我在使用 fastcgi++ 2 beta session 时遇到问题。

这是我的代码:

#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;\r\n\r\n";
        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();

我正在使用 this tutorial .

感谢您的帮助。

最佳答案

static Sessions<string> sessions;仅在类中声明;您需要为其创建一个定义。在这种情况下,我相信坚持 Sessions<string> SessionsPage::sessions;考虑到该类(class)仅在一个翻译单元中使用,您的类(class)就可以了。 (如果你在多个翻译单元中使用它,静态变量必须在一个并且只有一个翻译单元中定义)

关于c++ - 使用带有 fastcgi++ 的 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6365414/

相关文章:

c++ - 从 cvFindContour 中提取对象

c++ - websocket++ 使用 fastcgi++ 的 session 示例

c++ - enable_if 和构造函数与 VS2012

python - 在 C++ 中使用 MinGW 嵌入 python3.6 链接失败

apache - 在curl中传递POST数据时请求实体太大

c++ - libfastcgipp < 加载共享库时出错

jquery - 使用 fastcgi++ 和 json-spirit 读取和解析 POST JSON

c++ - XCode 9.3 升级或替换 libc++

c++ - Boost.Tests 入口点在哪里?