Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
13
Help us understand the problem. What is going on with this article?
@mkimura81

C++用マイクロウェブフレームワークcrow入門(Hello,Worldまで)

More than 3 years have passed since last update.

C/C++用のウェブフレームワークcrowを使ってみます。

crow

プロジェクトディレクトリ作成

$ mkdir crow_example
$ cd crow_example

crowインストール

chpplが使える人

http://qiita.com/noco/items/4e4ca6c6abac99d19619

$ chppl download crow

使えない人

crowのGitHubからcrow_all.hをダウンロードしてくる

test_app.cpp作成

test_app.cpp
#include "crow_all.h"

int main() {
  crow::SimpleApp app;

  CROW_ROUTE(app, "/")([](){
      return "Hello, World!";
  });

  app.port(8080).multithreaded().run();
}

CMakeLists.txt作成

CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project (crow_examples)

find_package(Threads)

if (NOT CMAKE_BUILD_TYPE)
    message(STATUS "No build type selected, default to Release")
    set(CMAKE_BUILD_TYPE "Release")
endif()


if (MSVC)
set(Boost_USE_STATIC_LIBS "On")
find_package( Boost 1.52 COMPONENTS date_time filesystem system thread regex REQUIRED )
else()
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++1y")
find_package( Boost 1.52 COMPONENTS date_time filesystem system thread REQUIRED )
endif()

include_directories( ${Boost_INCLUDE_DIR} )

set(PROJECT_INCLUDE_DIR
${PROJECT_SOURCE_DIR}/include
)

include_directories("${PROJECT_INCLUDE_DIR}")
include_directories("${PROJECT_SOURCE_DIR}")

add_executable(test_app test_app.cpp)
target_link_libraries(test_app ${Boost_LIBRARIES})
target_link_libraries(test_app ${CMAKE_THREAD_LIBS_INIT})

ビルド

$ cmake .
$ make

起動

$ ./test_app

http://localhost:8080
にアクセスして"Hello, World!"が表示されていることを確認

以上で終了です。お疲れ様でした。

13
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
13
Help us understand the problem. What is going on with this article?