• ベストアンサー

Cygwin boost

Windows XP sp2 + Cygwin の C++ で正規表現を使いたく setup.exe で boost をインストールし、以下のコードをコンパイル($g++ regextest.cpp) したのですがエラーが出てしまいました。 コード: #include <boost/regex.hpp> #include <iostream> using namespace std; int main () { string str("Free Programming For Windows."); boost::regex reg("Free.+Windows\\."); if (boost::regex_match(str, reg)) { cout << "===> Matched." << endl; } else { cout << "===> Not matched." << endl; } return 0; } エラー: regextest.cpp:1:27: boost/regex.hpp: No such file or directory パスが通っていないようなのですが、どうしたらよいか分かりません。アドバイスいただけたら嬉しいです。 usr/include/boost-1_33_1 に boost/regex.hpp は確認できました。

  • SE-1
  • お礼率71% (10/14)

質問者が選んだベストアンサー

  • ベストアンサー
  • jacta
  • ベストアンサー率26% (845/3158)
回答No.2

正規表現を使うのであれば、インクルードパスの設定のほかに、-lboost_regex-gcc-mtまたは-lboost_regex-gcc-mt-sオプションを付けて、ライブラリをリンクしてやる必要があります。

SE-1
質問者

お礼

有難うございます。お教えいただいたようにオプションをつけたのですが以下のようなエラーがでてしまいました。まだ C++ を使い始めたばかりで明らかに基礎知識が不足しているので、良く勉強してから再挑戦したいと思います。今回はコンパイルオプションの勉強ができてよかったです。 /cygdrive/c/xxxx/Temp/ccjcOj70.o:regextest.cpp:(.text$_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7 _j[boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<ch (略

その他の回答 (4)

  • jacta
  • ベストアンサー率26% (845/3158)
回答No.5

実際に使用したコマンドも補足してください。 それから、念のためCygwinも最新の内容に更新してみてください。

SE-1
質問者

お礼

補足内での質問の件は無視してください・・・私の勘違いでした。 boost::regex_match を boost::regex_search とすればいいんですね・・  ご親切なご回答のおかげで無事動くようになりました。有難うございました!

SE-1
質問者

補足

コマンド記入し忘れ、さらにお返事遅れてすみません。 g++ -I "C:\cygwin\usr\include\boost-1_33_1" -lboost_regex-gcc-mt regextest.cpp コマンドは↑でした・・お恥ずかしいのですが、ライブラリはファイル名の後に指定することを知りませんでした。で、 g++ -I "C:\cygwin\usr\include\boost-1_33_1" regextest.cpp -lboost_regex-gcc-mt とするとコンパイルできました。でも実行すると出力が Not matched となってしまいました・・・今度は何がいけないんでしょうか・・・ boost::regex reg("Free"); を boost::regex reg(".+"); とすると Matched がでました。

  • jacta
  • ベストアンサー率26% (845/3158)
回答No.4

質問文のソースコードを実際にCygwinでコンパイルしてみましたが、エラーにはなりませんでした。 実際に使用したコマンド、それからBoost C++ Librariesのバージョン(Cygwinの場合はboost-1_33_1-1とか枝番があるはずです)、GCCとBinutilsとNewlibのバージョンを補足してください。 もし、GCCやBinutilsをご自身でソースからインストールした場合、バージョン(cygming specialかどうかも)以外に、configure時に指定したオプションも補足してください。

SE-1
質問者

補足

ご親切に感謝いたします。以下バージョン情報です。 Boost: 1.33.1 gcc: 3.4.4 newlib: 1.14.0 binutils: binutils.lst.gz というのがあるだけでバージョン情報は分かりませんでした。これが問題なんでしょうか。 以上 cygwin の setup.exe でインストールしています。

  • jacta
  • ベストアンサー率26% (845/3158)
回答No.3

> /cygdrive/c/xxxx/Temp/ccjcOj70.o:regextest.cpp:(.text$_ZN5boost11basic_regexIcNS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE6assignEPKcS7 _j[boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<ch (略 肝心の部分を省略しないでください。 エラーメッセージは、どんなに長ったらしくても全文記載するのが基本です。

SE-1
質問者

補足

マナーを知らず大変失礼いたしました。以下エラーメッセージです。 /cygdrive/c/DOCUME~1/xxx/Temp/cc5KgyTU.o:regextest.cpp:(.text$_ZN5 boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_m atchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEEC1ES6_S6_RNS_13match_r esultsIS6_S9_EERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsES6_[b oost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::bas ic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator <boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<ch ar, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<ch ar, boost::cpp_regex_traits<char> > >::perl_matcher(__gnu_cxx::__normal_iterator <char const*, std::basic_string<char, std::char_traits<char>, std::allocator<cha r> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::c har_traits<char>, std::allocator<char> > >, boost::match_results<__gnu_cxx::__no rmal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std:: allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterato r<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<ch ar> > > > > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_re gex_traits<char> > > const&, boost::regex_constants::_match_flags, __gnu_cxx::__ normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std ::allocator<char> > >)]+0x110): undefined reference to `boost::re_detail::perl_m atcher<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::ch ar_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu _cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<ch ar>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_tr aits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char , boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags )' collect2: ld returned 1 exit status

回答No.1

-I オプションでinclude-pathを指定するだけじゃないんですか?

SE-1
質問者

お礼

ご回答ありがとうございました。regex 等は#2さまご指摘のように別途 -l オプションが必要なようですが、他のライブラリは認識されうまくいきました。

関連するQ&A

  • cygwinでのboost

    cygwin上でboostを用いたいんですが、うまくいきません。 test.cppで、#include<boost/ramdom.hpp>としており、 コマンドを、 $ g++ -I"C:\cygwin\usr\include\boost-1_33_1" test.cpp とすると boost/ramdom.hpp: No such file or directory となってしまいます。 ramdomがboost-1_33_1の中にあるのは確認してます。 いろいろ調べてみたんですが上手くいきません。 よろしくお願いします。

  • boost::formatの値をstring型にコピーしたい

    boost::formatの値をstring型にコピーしたいのですが、うまくいきません。boost自体初めてで以下のサイトからダウンロードし、展開後VS2005のVCのインクルードフォルダーにboostフォルダーをまるまるコピーしただけですが・・・ http://sourceforge.net/project/showfiles.php?group_id=7586 boost 1.34.1 #include <iostream> #include <boost/format.hpp> using namespace std; using boost::format; void main(){ double x = 1.234; string str("abc"); //cout << format("%10.3f, [%16s]") % x % str << endl; // サンプルはこうでした。 // いったんstring型に入れて表示させたい。 string y; y = boost::format("%10.3f, [%16s]") % x % str; // エラー箇所 std::cout << y << std::endl; }

  • boost::regexで、日本語に利用ついて

    boost_1_47を利用して、置換を行おうとしているのですが、「VIII」を置換しようとするとエラーになります。たぶん「5B」が入っているからかと思うのですが、どのように対処したらよいのでしょうか? #include <boost/regex.hpp> using namespace std; using namespace boost; const boost::regex str("VIII"); よろしくお願いします。

  • clangで例外がキャッチできない?

    初質問です.yahooでも質問したのですがこちらでもしておきます. 趣味でプログラミングをしているものです.clang(コンパイラです)はエラーメッセージが分かりやすいので使っていたのですがg++と挙動が違うようです. 以下のソースのようにC++でboost::lexical_castを使おうとしたのですが,変換に失敗した際に,g++では例外をキャッチしてくれるのにclang(コンパイラです)ではキャッチしてくれず,実効停止してしまうようです.コンパイラオプションの問題でしょうか? ~ ソース test3.cpp ~ #include <iostream> #include <boost/lexical_cast.hpp> #include <string> using namespace std; int main() {     cout << "start" << endl; try { throw 10; // これはキャッチしてくれる } catch (int i) { cout << "thrown:" << i << endl; } cout << "and..." << endl; string str = "not a number"; try { int error = boost::lexical_cast<int>(str); } catch(boost::bad_lexical_cast& e) { // 以下,clangだと全部スルー? cout << "bad_lexical_cast!!" << endl; cout << e.what() << endl; } catch(exception& e) { cout << "exception!!" << endl; cout << e.what() << endl; } catch(...) { cout << "exception!?" << endl; cout << "error" << endl; } cout << "end" << endl; } ~ コンパイル&実行 ~ > clang test3.cpp -lstdc++ -I"C:\Program Files (x86)\boost\boost_1_47" > a.out start thrown:10 and... This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. > g++ test3.cpp -I"C:\Program Files (x86)\boost\boost_1_47" > a.exe start thrown:10 and... bad_lexical_cast!! bad lexical cast: source type value could not be interpreted as target end > ~ 環境 ~ OS:Windows 7 clang:version 3.1 g++(mingw):version 4.6.1(あ,でもインストール適当なんで4.7とかとかぶってるかもです) boost:version 1.4.7(1.0っていうんですかね?) 何か激しく勘違いをしている可能性もあるのでお暇な方はどうぞ教えてください. P.S. なんとインデントが消えてしまうのですね!

  • xpressive.hpp をオープンできない

    現在、code gear c++ builder 2009 でboostに関するプログラムを勉強してます。 正規表現のプログラムをやってみたくて、インクルードファイルとして、 #include <boost/xpressive/xpressive.hpp> こちらを宣言したのですが、次のようなエラーが出てきました。 [BCC32 エラー] test_boost.cpp(12): E2209 インクルード ファイル 'boost/xpressive/xpressive.hpp' をオープンできない [BCC32 エラー] test_boost.cpp(14): E2316 'xpressive' は 'boost' のメンバではない [BCC32 エラー] test_boost.cpp(14): E2282 名前空間名が必要 このようなエラーが出てくるのですが、これを解決する方法はないでしょうか? どうぞ、ご教授の程よろしくお願い致します。

  • boost::serializationについて

    次のコードがテンプレート辺りでコンパイルできません #include <list> #include <array> #include <fstream> #include <boost/serialization/serialization.hpp> #include <boost/serialization/array.hpp> #include <boost/serialization/list.hpp> #include <boost/archive/binary_iarchive.hpp> #include <boost/archive/binary_oarchive.hpp> std::list<std::array<bool, 3>> lab; std::array<bool, 3> pusharray; pusharray[0] = true; pusharray[1] = false; pusharray[2] = true; lab.push_back(pusharray); lab.push_back(pusharray); std::ofstream ofs("test"); boost::archive::binary_oarchive boa(ofs); boa << lab; ofs.close(); std::ifstream ifs("test"); boost::archive::binary_iarchive bia(ifs); bia >> lab; ifs.close(); エラーメッセージ: c:\program files\microsoft visual studio 10.0\vc\include\boost\archive\basic_binary_iprimitive.hpp(181): warning C4244: '引数' : 'std::streamsize' から 'size_t' への変換です。データが失われる可能性があります。 c:\program files\microsoft visual studio 10.0\vc\include\boost\archive\basic_binary_iprimitive.hpp(152): クラス テンプレート のメンバー関数 'void boost::archive::basic_binary_iprimitive<Archive,Elem,Tr>::load_binary(void *,size_t)' のコンパイル中 with [ Archive=boost::archive::naked_binary_iarchive, Elem=char, Tr=std::char_traits<char> ] c:\program files\microsoft visual studio 10.0\vc\include\boost\archive\detail\iserializer.hpp(362) : コンパイルされたクラスの テンプレート のインスタンス化 'void boost::archive::load_access::load_primitive<Archive,T>(Archive &,T &)' の参照を確認してください with [ Archive=boost::archive::naked_binary_iarchive, T=boost::archive::object_id_type ] (略) そもそもSTLコンテナのネストはserializeできないのでしょうか それともヘッダが足りないのでしょうか

  • C++のファイルの分割について教えてください。

    分割したプログラムの書き方を練習中なのですが、 下のようなプログラムを書いて、ビルドしようとしたら失敗します。 どこが悪いのか、教えていただけないでしょうか? (5)\test30\Debug\test30.exe : fatal error LNK1120: 外部参照 1 が未解決です。 1>test30 - エラー 2、警告 0 ========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ========== //test30.cpp #include <iostream> #include "sub.h" int main(void) { std::cout<<"メインプログラムです。"<<std::endl; sub1(); sub2(); return 0; } ------------------------------------------------------------- //sub1.cpp #include <iostream> void sub1(void) { std::cout<<"サブ1です。"<<std::endl; } ------------------------------------------------------------- //sub2.cpp #include <iostream> void sub1(void) { std::cout<<"サブ2です。"<<std::endl; } --------------------------------------------------------------- //sub.h void sub1(void); void sub2(void);

  • C++のiostreamのインクルードが不可能です

    C++のiostreamのインクルードが不可能です。 とても初歩的な話でお恥ずかしいのですが、 Visual Studio 2012 Express for Windows DesktopにてC++の入門をしようとしている者です。 入門書の通り、iostreamをインクルードしてnamespaceをstdにして int main() { cout << "Hello, World!" << endl; return 0; } このようなHello,World!コードを作ったのですが、エラーが発生し、 ・ソースファイルを開けません "iostream" ・識別子 "cout", "endl" が定義されていません と表示され、デバッグエラーとなります。 プロジェクトの作り手順としては C++の空のプロジェクトからcppファイルをソースファイルに追加する手順です。 どなたか解決方法をご教授ください。

  • C++のソースに関する質問

    以下のコードをコンパイラのテスト目的でコンパイルしました //test.cpp #include <iostream> using namespace std; void main() { cout << "test" << endl; } 使っているコンパイラはBCC Developerと言うソフトです 上に書いているコードは間違っては居ないと思うのですが エラー E2266: ファイル名が指定されていない と言うエラーが出てきます、何処のファイルをどうやって 指定するのかを教えてください

  • stringについて

    C++初心者です。 このプログラムで続行するとエラーがでます。どうしたら無事実行することが出来るのでしょうか? #include<stdio.h> #include <iostream> using namespace std; int main(void) { string str("エラー"); cout << str<< endl; } エラー 1>c:\documents and settings\****\デスクトップ\zisyu12\zisyu12\main.cpp(58) : error C2679: 二項演算子 '<<' : 型 'std::string' の右オペランドを扱う演算子が見つかりません (または変換できません)。 . . . 以下省略

専門家に質問してみよう