はじめに
MacでC++のopencv環境を構築する場合,g++でなくてcmakeを利用するようなので,その時行ったことをメモしました.
手順
1. cmakeのインストール
homebrewでcmakeをインストール.
$ brew install cmake
2. テスト環境の作成
以下のように,test.cppとCMakeLists.txtを作成.
.
├── CMakeLists.txt
└── test.cpp
test.cppにテスト用に以下のコードを記述.
# include <iostream>
using namespace std;
int main(){
string name;
cin >> name;
cout << "Hello, " + name << endl;
}
CMakeLists.txtに以下を記述.(一例)
cmake_minimum_required(VERSION 2.8)
add_executable(Main test.cpp)
3. 動作確認
以下のコマンドを実行.
cmake .
make
./Main
実行して,標準入力でnameを入力した後,"Hello, name"が出力されればおけ.
なお,./Mainは,add_executable(Main test.cpp)のMain.