LoginSignup
12
12

More than 5 years have passed since last update.

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

Last updated at Posted at 2016-07-05

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!"が表示されていることを確認

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

12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12