11
4

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.

C++ のライブラリーBoostをインストールしterminalでコンパイルするまで(Mac)

Posted at

http://www.boost.org/doc/libs/1_61_0/more/getting_started/unix-variants.html
Boostの説明は省きます。
Homebrewを用いてインストールできます。
$ brew install boost

Error: boost-1.58.0 already installed
To install this version, first `brew unlink boost`

もし上のようなエラーが出てきたら
$ brew doctor boost
でインストールされている場所を見ましょう。

/usr/local/Cellar/boost/1.58.0 (10,718 files, 462.2M) *

これをどこかにコピーしておき、コンパイル時に使います。
適当に好きなエディターでboostのテストを作ってみましょう。

#include <boost/ptr_container/ptr_list.hpp>
#include <iostream>

using namespace std;

class foo
{
private:
   int Num;
public:
  foo() : Num(0){}//default Constructor
  explicit foo(int a): Num(a){}
  ~foo(){cout << "Destructed" << endl;} // destructor
  void print() {cout << Num << endl;}
};

int main()
{
  boost::ptr_list<foo> ls;
  boost::ptr_list<foo>::iterator itls;

  ls.push_back(new foo());
  ls.push_back(new foo(1));
  ls.push_back(new foo(2));

  for (itls = ls.begin();
       itls != ls.end();
       itls++)
    {
      itls->print();
    }

  ls.clear(); // All pointers held in list are deleted.
}

こんな感じで適当にテストプログラムを書き
コンパイルはとりあえず今回はg++で
$ g++ -I /usr/local/Cellar/boost/1.58.0 test1.cpp -o test1
g++ -I /あなたのpath / プログラム名 -o コンパイル後のファイル名

こんな感じでboostが使えます。

11
4
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
11
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?