1

fcgi と nginx を使用して C++11 で Web サイトを作成したいと考えています。現時点では、libc++ と組み合わせた Clang++ のみが C++11 を完全にサポートしています。

しかし、私の fcgi プログラムを実行すると、誰かがブラウザでページをリクエストすると、セグメンテーション違反が発生します。

テストコード:

#include <iostream>
#include <sstream>

#include "fcgio.h"


int main() {
    int count = 0;

    FCGX_Request request;

    FCGX_Init();
    FCGX_InitRequest(&request, 0, 0);

    while(FCGX_Accept_r(&request) == 0) {
        fcgi_streambuf cout_fcgi_streambuf(request.out);

        std::ostream fout(&cout_fcgi_streambuf);

        fout << "Content-type: text/html\r\n" <<
               "\r\n" <<
               "<title>CGI Hello!</title>" <<
               "<h1>CGI Hello!</h1>" <<
               "Request number" << ++count << "\n" << std::endl;
    }

    return 0;
}

上記のコードは、次のようにコンパイルされています。

clang++ -stdlib=libc++ -o index index.cpp -lfcgi++ -lfcgi -std=c++11 -g

gdb は次を出力します。

Program received signal SIGSEGV, Segmentation fault.
0x0000000000402bd9 in sputc (this=0x7fffffffe4d0, __c1=0, __c=10 '\n', __c2=4210300) at /usr/include/c++/v1/streambuf:351
351     *__nout_++ = __c;

-stdlib=libc++ なしでコンパイルすると、一部の C++11 機能を使用できないことを除いて、すべて正常に動作します...</p>

クラッシュせずに fcgi-app を実行して libc++ を使用する方法はありますか?

4

1 に答える 1