7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

XcodeでBoost C++ Libraries #include <boost/asio.hpp> のコンパイルを通したい!

Last updated at Posted at 2014-12-24

#Homebrewを使ったboostのインストール

brew install boost

#XCODE 設定

##PROJECT

###Header Search Paths

/usr/local/Cellar/boost/1.56.0/include

###Library Search Paths

/usr/local/Cellar/boost/1.56.0/lib

※バージョンによって1.56.0の部分は変わります。

##TARGETS
###Other Linker Flags:

-lboost_system

##C++ サンプル

main.cpp
#include <iostream>
#include <boost/asio.hpp>

namespace asio = boost::asio;
using asio::ip::tcp;

int main(int argc, const char * argv[]) {
    
    asio::io_service io_service;
    tcp::socket socket(io_service);
    
    // 接続
    socket.connect(tcp::endpoint(asio::ip::address::from_string("127.0.0.1"), 54321));
    
    // メッセージ送信
    const std::string msg = "ping";
    boost::system::error_code error;
    asio::write(socket, asio::buffer(msg), error);
    
    if (error) {
        std::cout << "send failed: " << error.message() << std::endl;
    }
    else {
        std::cout << "send correct!" << std::endl;
    }
    
    return 0;
}

boostjp - ネットワーク - TCP メッセージ送信

7
5
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
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?