Mac OS X Leopard で Boost.Filesystem を使う
Boost.Filesystemライブラリを使ったプログラムをMacでコンパイルしようとしてもそのままではエラーが出てコンパイルできない。コンパイルするためには-lオプションを用いて、「libboost_system-mt」と「libboost_filesystem-mt」を明示的にリンクする必要がある。
ちなみにBoostのバーションは1.37.0、MacPortsでインストールしたものです。
"test.cpp"
#include <boost/filesystem.hpp> using namespace boost::filesystem; int main() { path test("test"); if(!exists(test)){ create_directory(test); } return 0; }
g++ -lboost_system-mt -lboost_filesystem-mt test.cpp
下は普通にコンパイルした場合
g++ test.cpp Undefined symbols: "boost::system::get_generic_category()", referenced from: __static_initialization_and_destruction_0(int, int)in ccbI5DkO.o __static_initialization_and_destruction_0(int, int)in ccbI5DkO.o __static_initialization_and_destruction_0(int, int)in ccbI5DkO.o "boost::system::get_system_category()", referenced from: boost::system::error_code::error_code()in ccbI5DkO.o __static_initialization_and_destruction_0(int, int)in ccbI5DkO.o __static_initialization_and_destruction_0(int, int)in ccbI5DkO.o "boost::filesystem::detail::create_directory_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from: boost::enable_if<boost::filesystem::is_basic_path<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >, bool>::type boost::filesystem::create_directory<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)in ccbI5DkO.o "boost::filesystem::detail::status_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::system::error_code&)", referenced from: boost::enable_if<boost::filesystem::is_basic_path<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >, bool>::type boost::filesystem::exists<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)in ccbI5DkO.o ld: symbol(s) not found collect2: ld returned 1 exit status