MacPorts(@snow leopardです)でboostをインストールして動かすまで

sudo port install boost

※build重いです。長いです。

port由来のバイナリとライブラリにパスを通す。

boostにとって何が効いているのかはよくわかんね。全部じゃないとおもふ。
http://d.hatena.ne.jp/aduka/20081222/1229909299をコピペ。
@~/.bashrcと~/.zshrc

export PATH=/opt/local/bin:/opt/local/sbin/:$PATH
export MANPATH=/opt/local/man:$MANPATH
export LIBRARY_PATH=/opt/local/lib:$LIBRARY_PATH
export LD_LIBRARY_PATH=/opt/local/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=/opt/local/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/opt/local/include:$CPLUS_INCLUDE_PATH
export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib
export BOOST_ROOT=/opt/local/include/boost:$BOOST_ROOT

xcodeとかだとVisualStudioみたいにGUIで設定するのだとか。。。
ですよねぇ。。


確認
http://www.kmonos.net/alang/boost/classes/bind.htmlのソース

#include <iostream>
#include <string>
#include <iterator>
#include <functional>
#include <algorithm>
#include <boost/bind.hpp>

using namespace std;

bool is_ordered(int a,int b,int c)
{
	return a <= b && b <= c;
}	
int main()
{
	//7以上12以下の最初の要素を探す。
	//is_orderedに定数をbindした関数オブジェクトを作っている?
	{
		int arr[] = {1,2,3,4,5,6,7,8,9,10};
		const int len = sizeof(arr) / sizeof(arr[0]);
		int* f = find_if(arr,
										 arr+len,
										 boost::bind(is_ordered,7,_1,12)
										 );
		cout << *f << endl;
	}
	return 0;
}

大丈夫そうですね。どうでもいいけど*fでcallしてるのか?評価時点がいつなのかよくわかんね。コンパイル時?よくわかんね。。調べないと。


emacs flymakeにも同様にboostのパスを通す。
このままだとflymakeがもうずっとエラー状態なのでイラッ☆します。
基本はsetenvでいいのかしら。ググりました。
@.emacs
http://d.hatena.ne.jp/syou6162/20081216/1229377127をコピペ

;;boost
(setenv "CPLUS_INCLUDE_PATH" "/opt/local/include:$CPLUS_INCLUDE_PATH")

boostに効いてイルのはCPLUS_INCLUDE_PATHが効いているのですね


テスト
M-x eshellにて変数がとれているのか確認(M-x shellとかだと.bashrc通りますしね。flaymakeはどこからコンパイラをたたいてるかわかんない。少なくともemacs->は確かなので。)

[.emacs設定前]
$ c++ ./boost_bind.cpp && ./a.out
./boost_bind.cpp:6:26: error: boost/bind.hpp: No such file or directory
./boost_bind.cpp: In function 'int main()':
./boost_bind.cpp:23: error: 'boost' has not been declared
./boost_bind.cpp:23: error: '_1' was not declared in this scope
[.emacs設定後]
$ c++ ./boost_bind.cpp && ./a.out
7

大丈夫そうですよね。flaymakeもおこらなくなりましたとさ。

さぁて。満足したのでC++はもう書きますん。