我的操作系统:Mac OSX
我的 gcc 版本:4.2.1
我的 clang 版本:llvm 6.1.0
cppcms 版本:1.0.5
我下载了 cppcms 框架并安装了框架。命令:cd cppcms-1.0.5
mkdir build & cd build
cmake ..
make
make test
make install
未发现错误。我写了一个名为hello.cpp的cpp文件。程序是这样的:
#include <cppcms/application.h>
#include <cppcms/applications_pool.h>
#include <cppcms/service.h>
#include <cppcms/http_response.h>
#include <iostream>
using namespace std;
class hello : public cppcms::application{
public:
hello(cppcms::service &srv) : cppcms::application(srv){
}
virtual void main(std::string url);
};
void hello::main(std::string /*url*/)
{
response().out() <<
"<html>\n"
"<body>\n"
" <h1>Hello World</h1>\n"
"</body>\n"
"</html>\n";
}
int main(int argc,char ** argv) {
try {
cppcms::service srv(argc,argv);
srv.applications_pool().mount(
cppcms::applications_factory<hello>()
);
}
catch (std::exception const &e){
std::cerr << e.what() << std::endl;
}
return 0;
}
我的 config.js:
{
"service" : {
"api" : "http",
"port" : 8008
},
"http" : {
"script_names" : [ "/hello" ]
}
}
编译命令:
c++ hello.cpp -lcppcms -o hello
./hello -c config.js
我访问了网址“ http://localhost:8008/hello ”,然后浏览器显示给我
"This webpage is not available".
怎么了?如何解决问题。