boost::filesystemのコンパイルエラーを解決する方法

このQ&Aのポイント
  • Mac OS Xでboost::filesystemのコンパイルをしようとするとエラーが発生します。
  • エラーメッセージには、boost::system::generic_category()やboost::filesystem3::detail::file_size()が見つからないという内容が含まれています。
  • 一部の情報によると、コンパイル時に-lboost_system-mt -lboost_filesystem-mtオプションを付ければ解決できるとされていますが、ld: library not foundエラーが発生しています。
回答を見る
  • ベストアンサー

boost::filesystemのコンパイル

こんにちは。 現在boost::filesystemについて勉強しているのですが、サンプルプログラムを用いてコンパイルをしようとするとエラーが発生します。 OSは、Mac OS Xで、boostは1.46.1です。 インストール(bjamなど)は、完了しているはずです(できてなかったらごめんなさい) g++ test.cpp でコンパイルしようとすると以下のエラーメッセージが表示されます。 Undefined symbols: "boost::system::generic_category()", referenced from: __static_initialization_and_destruction_0(int, int)in ccv6DmNs.o __static_initialization_and_destruction_0(int, int)in ccv6DmNs.o "boost::system::system_category()", referenced from: __static_initialization_and_destruction_0(int, int)in ccv6DmNs.o "boost::filesystem3::detail::file_size(boost::filesystem3::path const&, boost::system::error_code*)", referenced from: boost::filesystem3::file_size(boost::filesystem3::path const&)in ccv6DmNs.o "boost::filesystem3::path::wchar_t_codecvt_facet()", referenced from: boost::filesystem3::path::codecvt() in ccv6DmNs.o ld: symbol(s) not found collect2: ld returned 1 exit status また、上記のエラーの一部を検索をかけて調べたところ g++ -lboost_system-mt -lboost_filesystem-mt test.cpp とコンパイルすればできると書かれていたのですが、 ld: library not found for -lboost_system-mt collect2: ld returned 1 exit status と表示されて、コンパイルできませんでした。 どうすればいいのかわからないので、教えて下さい。 よろしくお願いします。

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

  • ベストアンサー
  • kmee
  • ベストアンサー率55% (1857/3366)
回答No.1

boostは、どんな方法でどこにインストールしましたか? -lboost_system-mt は libboost_system-mt.a をリンクしようとします。インストールしたディレクトリの下の方に libboost_system-mt.a があるのではないでしょうか。そのディレクトリを-Lで指定するようにするとどうでしょうか。

morappe
質問者

お礼

いろいろありがとうございました。 いくつか試してみたところ、libboost_system.aというのが存在し、mtというのがなかったので コンパイル時にも、mtを省いたらコンパイルすることが出来ました。 本当にありがとうございました!

morappe
質問者

補足

回答ありがとうございます。 boostは、boostのHPからダウンロードし、それを ./bootstrap.sh ./bjam を実行しました。 場所は、boostという名のフォルダを作成して、その中に入れました。 確認したところ、libboost_system.aというのがありました。 ディレクトリを-Lで指定する方法も教えていただけるとありがたいです。 お手数ですが、よろしくおねがいします。

関連するQ&A

  • Xcodeでコンパイルエラーが出たときの調べ方

    iPhone向けのメーラーを作ってみようと思い、LibEtPan というライブラリをGitHubから ダウンロードして、以下のURLにある pop-sample.c のサンプルコードを使ってみたところ エラーが出ました。 結論からいうとエラーメッセージをそのままネットで調べて、とりあえずコンパイルエラーは 発生しなくなり、無事、ライブラリを使う事はできたのですが、なぜ動くようになったのか、 今のコンパイルエラーが出ていない状態がはたして正しいのかがわかっておりません。 以下、エラー発生までのプロセスです。 1、新規でiPhone向けプロジェクトを作成 2、libEtPanをサブプロジェクトとして追加 3、libetpan-ios.a をLinkに追加 4、Other Linker Flagsに -lsasl2 を設定 5、pop-sample.cのサンプルコードをコピー (サンプルコード内にあるファイル書き込みの処理はコンソールにメール内容を表示する処理に置き換えた) 手順3と4は以下GitHubのREADMEに書いてある手順です。 https://github.com/dinhviethoa/libetpan この状態でビルドすると、以下のようなエラーが発生しました。 Undefined symbols for architecture i386: "_SecCertificateCopyData", referenced from: _mailstream_low_cfstream_get_certificate_chain in libetpan-ios.a(mailstream_cfstream.o) "_deflate", referenced from: _mailstream_low_compress_write in libetpan-ios.a(mailstream_compress.o) "_deflateEnd", referenced from: _mailstream_low_compress_open in libetpan-ios.a(mailstream_compress.o) _mailstream_low_compress_free in libetpan-ios.a(mailstream_compress.o) "_deflateInit2_", referenced from: _mailstream_low_compress_open in libetpan-ios.a(mailstream_compress.o) "_inflate", referenced from: _mailstream_low_compress_read in libetpan-ios.a(mailstream_compress.o) "_inflateEnd", referenced from: _mailstream_low_compress_open in libetpan-ios.a(mailstream_compress.o) _mailstream_low_compress_free in libetpan-ios.a(mailstream_compress.o) "_inflateInit2_", referenced from: _mailstream_low_compress_open in libetpan-ios.a(mailstream_compress.o) "_kCFStreamPropertySSLPeerCertificates", referenced from: _mailstream_cfstream_set_ssl_enabled in libetpan-ios.a(mailstream_cfstream.o) _mailstream_low_cfstream_get_certificate_chain in libetpan-ios.a(mailstream_cfstream.o) "_kCFStreamPropertySSLSettings", referenced from: _mailstream_cfstream_set_ssl_enabled in libetpan-ios.a(mailstream_cfstream.o) "_kCFStreamSSLAllowsAnyRoot", referenced from: _mailstream_cfstream_set_ssl_enabled in libetpan-ios.a(mailstream_cfstream.o) "_kCFStreamSSLAllowsExpiredCertificates", referenced from: _mailstream_cfstream_set_ssl_enabled in libetpan-ios.a(mailstream_cfstream.o) "_kCFStreamSSLAllowsExpiredRoots", referenced from: _mailstream_cfstream_set_ssl_enabled in libetpan-ios.a(mailstream_cfstream.o) "_kCFStreamSSLLevel", referenced from: _mailstream_cfstream_set_ssl_enabled in libetpan-ios.a(mailstream_cfstream.o) "_kCFStreamSSLValidatesCertificateChain", referenced from: _mailstream_cfstream_set_ssl_enabled in libetpan-ios.a(mailstream_cfstream.o) ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) そこで、上記のエラーメッセージをネットで検索し、結果的には以下のことをすることで、コンパイルエラーが 解消しました。 ・CFNetwork.framework と Security.framework のLink追加 ・Other Linker Flags に -lz の追加 そこで、質問ですが、熟練したプログラマは、上記のようなエラーが出たとき、 そのエラーメッセージからどういう情報を読み取り、どのようなプロセスで問題を 解決するのでしょうか? 私は、上記のエラーメッセージを見ても「Undefined symbols」というメッセージから 何かライブラリが足りないのかな?程度しか情報を読み取る事ができませんでした。 以上、よろしくお願いします。

  • C++のプログラムについて教えてください。

    C++のプログラムについて教えてください。 以下のようなプログラムでコンパイルを行うと、エラーが起きてしまい、原因が分かりません。 OSはMac OS X 10.6.4です。 プログラム //************************************ //main.cpp #include <iostream> class test{ private: static int num; public: test(); int get_num(); }; test::test(){ num=0; } int test::get_num(){ return num; } int main(){ test t; int num = t.get_num(); std::cout<<num<<std::endl; return (0); } //*********************************** g++ -o main main.cppでコンパイルした結果 Undefined symbols: "test::num", referenced from: test::test() in ccYWvIdB.o test::test() in ccYWvIdB.o test::get_num() in ccYWvIdB.o ld: symbol(s) not found collect2: ld returned 1 exit status のようにエラーが起きます。 どなたか分かる方がいればお願いします。

  • Mac C Undefined x86_64

    C言語の勉強中です。 大学にいたころにLinuxで作ったプログラミングを自分のMacで動かしてみようと思い、コンパイルをかけると、Undefined symbols for architecture x86_64とでました。これを解決したいです。MacOSX LionのIntel Core 2 duo です。僕の試したことを一通り書きます。 僕の動かしたいプログラムのソースの#includeに <FTGL/ftgl.h><GL/glfw.h> とか見慣れないのがあったので、 FTGLをmacportで入れて、glfwをダウンロードし、GLをGLUTに変えてコンパイル cc -I /opt/local/include project.c -o project -framework OpenGL -framework GLUT -lobjc (-I /opt/local/includehはFTGLの入っている場所です) project.c:10:23: error: GLUT/glfw.h: No such file or directory うん?glfw.hをGLUTの中にコピーしたのになぁ?とりあえず現在のディレクトリにglfw.hをコピーし#include "glfw.h"に変更し再びコンパイル Undefined symbols for architecture x86_64: "_ftglRenderFont", referenced from: _outtextxy in ccvINkhN.o "_glfwInit", referenced from: _main in ccvINkhN.o "_glfwOpenWindow", referenced from: _main in ccvINkhN.o "_ftglCreateExtrudeFont", referenced from: _main in ccvINkhN.o "_ftglSetFontFaceSize", referenced from: _main in ccvINkhN.o "_ftglSetFontDepth", referenced from: _main in ccvINkhN.o "_ftglSetFontOutset", referenced from: _main in ccvINkhN.o "_ftglSetFontCharMap", referenced from: _main in ccvINkhN.o "_glfwGetWindowParam", referenced from: _main in ccvINkhN.o "_glfwGetWindowSize", referenced from: _main in ccvINkhN.o "_glfwGetMouseButton", referenced from: _main in ccvINkhN.o "_glfwSwapBuffers", referenced from: _main in ccvINkhN.o "_glfwTerminate", referenced from: _main in ccvINkhN.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status x86_64はたしか64-bitとかそんな感じの意味だった気が?学校のパソコン古かったしなんか違うのかなー?と思い -m32 -I /opt/local/include project.c -o project -framework OpenGL -framework GLUT -lobjc としてコンパイルを試みると Undefined symbols for architecture i386: "_ftglRenderFont", referenced from: _outtextxy in ccePdBJk.o "_glfwInit", referenced from: _main in ccePdBJk.o "_glfwOpenWindow", referenced from: _main in ccePdBJk.o "_glfwGetKey", referenced from: _main in ccePdBJk.o "_ftglCreateExtrudeFont", referenced from: _main in ccePdBJk.o "_ftglSetFontFaceSize", referenced from: _main in ccePdBJk.o "_ftglSetFontDepth", referenced from: _main in ccePdBJk.o "_ftglSetFontOutset", referenced from: _main in ccePdBJk.o "_ftglSetFontCharMap", referenced from: _main in ccePdBJk.o "_glfwGetWindowParam", referenced from: _main in ccePdBJk.o "_glfwGetWindowSize", referenced from: _main in ccePdBJk.o "_glfwGetMouseButton", referenced from: _main in ccePdBJk.o "_glfwSwapBuffers", referenced from: _main in ccePdBJk.o "_glfwTerminate", referenced from: _main in ccePdBJk.o ld: symbol(s) not found for architecture i386 うん?よく分からないがたしかi386は32-bitの意??どっちでやってもダメ??? うる覚えの知識を乱用し 再起動時に「2と3」を押しっぱなしにして(32-bitになる?)からのコンパイル→失敗 「6と4」を押しっぱなしにしてみる→失敗 sudo systemsetup -setkernelbootarchitecture x86_64 →失敗 sudo systemsetup -setkernelbootarchitecture i386 →失敗 sudo systemsetup -setkernelbootarchitecture default →失敗(そりゃそうですよね) うーん、ためしに gcc -vと打ってみると Target: i686-apple-darwin11とか Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.1~22/src/configure --disable-checking --enable-werror --prefix=/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.1~22/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1 Thread model: posix とでてる よく分からないがi686とx86_64ばかりあるところからターゲットは64-bitで作っている? 試しにコンパイルの通った実行ファイルに file test と打ってみる test: Mach-O 64-bit executable x86_64 おお確かにdefaultは64-bitのようだ!今度は同じファイルに対して-m32をつけてコンパイルして、file test test: Mach-O executable i386 うむ。-m32も仕事をしているよう。 これはbitの違いではなく、ダウンロードしたやつのせいとか、僕の置き場所が悪いとか、あるいは別の原因なのでしょうか?レベルの低い質問ですいません。回答お待ちしております。

  • Xcodeでのエラーについて

    MacでOpenCVを利用してKinectを扱おうとしているのですが、以下のようなエラーが出ました。 ちょっと自分には解決できないのですが、どうすればいいか教えてください。 言語はC++です。 Undefined symbols for architecture x86_64: "_cvCreateImage", referenced from: _main in main.o "_cvCvtColor", referenced from: _main in main.o "_cvReleaseImage", referenced from: _main in main.o "_cvShowImage", referenced from: _main in main.o "_cvWaitKey", referenced from: _main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

  • コンパイルはできるのに・・・・

    import java.io.*; public class ex32 { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int x = (new Integer(in.readLine())).intValue(); int y = (new Integer(in.readLine())).intValue(); while(x != y) { System.out.print("int x> "); System.out.print("int y> "); if(x > y) { x = x - y; } else{ y = y - x; } } System.out.println("GCM = " + x); } } このソースで、コンパイルとdouble x >の出力まではできるのですが、 そこで数字を入力してエンターを押すと、そこから進みません。 どう直したらいいでしょうか。

    • ベストアンサー
    • Java
  • 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 は確認できました。

  • mysql/rubyのインストールが出来ません。

    OS:MacOSX10.5.1 ruby:1.8.6 rails:2.0.2 macにmysql/rubyをインストールしようとしているのですがmakeすることが出来ず困っています。エラー内容は以下の通りです Macintosh:mysql-ruby-2.7.3 atsuhiroteshima$ make cc -arch ppc -arch i386 -pipe -bundle -o mysql.bundle mysql.o -L"." -L"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib" -L. -arch ppc -arch i386 -lruby -L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm -lpthread -ldl -lm ld: warning in /usr/local/mysql/lib/mysql/libmysqlclient.dylib, file is not of required architecture Undefined symbols for architecture ppc: "_mysql_store_result", referenced from: _store_result in mysql.o _query in mysql.o "_mysql_stmt_errno", referenced from: _mysql_stmt_raise in mysql.o _stmt_prepare in mysql.o _stmt_result_metadata in mysql.o "_mysql_stmt_error", referenced from: _mysql_stmt_raise in mysql.o "_mysql_options", referenced from: _options in mysql.o      (中略) "_mysql_fetch_field", referenced from: _fetch_field in mysql.o "_mysql_get_proto_info", referenced from: _proto_info in mysql.o "_mysql_errno", referenced from: _mysql_raise in mysql.o _my_errno in mysql.o "_mysql_error", referenced from: _mysql_raise in mysql.o _my_error in mysql.o "_mysql_escape_string", referenced from: _escape_string in mysql.o ld: symbol(s) not found for architecture ppc collect2: ld returned 1 exit status lipo: can't open input file: /var/folders/+b/+b2BrDwnESy62VzzTJy9k++++TI/-Tmp-//cc8ile28.out (No such file or directory) make: *** [mysql.bundle] Error 1 どなたかこのエラーの解決方法を教えていただけないでしょうか。 お願いします。

  • boost::archive::xml_oarchiveについて

    boostのコンパイルが通りません。調べられるだけ調べたのですが、原因として表示されるmake_nvpを利用しても、boost::STATIC_ASSERTION_FAILUREが発生します。わかる方ご教授お願いします。 #define BOOST_LIB_NAME boost_serialization #include <boost/config/auto_link.hpp> #include <boost/serialization/string.hpp> #include <boost/serialization/access.hpp> #include <boost/serialization/nvp.hpp> #include <boost/archive/xml_oarchive.hpp> #include <fstream> class FooData { private: int Data; friend class boost::serialization::access; template <class Archive> void serialization(Archive& ar, const unsigned int version) { ar & boost::serialization::make_nvp("Data",Data) } }; void main(void) { FooData data; //アーカイブ作成 std::ofstream ofs("output.txt"); boost::archive::xml_oarchive oa(ofs); // ファイル書き出し oa << (const FooData&)data; ofs.close(); }

  • C# この文法でコンパイルが通らないのは何故?

    下記のような2つのプログラムがあり、一方はコンパイルが通らず、もう一方はコンパイルが通ります。 文法上の違いはさほどないと思うのですが、何故このような結果になるのでしょうか? /////////////////////////コンパイルNG///////////////////////// using System; class Class1{ public static void Main(){ Class2 x; //違い! Class2 xをここで定義 try{x = new Class2(100);} catch{} Console.WriteLine(x.z); } } class Class2{ public int z; public Class2(int x){ z=x; } } /////////////////////////////////////////////////////////// /////////////////////////コンパイルOK///////////////////////// using System; class Class1{ static Class2 x; //違い! Class2 xをここで定義 public static void Main(){ try{x = new Class2(100);} catch{} Console.WriteLine(x.z); } } class Class2{ public int z; public Class2(int x){ z=x; } } ///////////////////////////////////////////////////////////

  • プログラミングのコンパイルで・・・・・

    C言語でのコンパイルで /tmp/cckxNO3W.o(.text+0xce): In function `main': : undefined reference to `hukeisan' collect2: ld はステータス 1 で終了しました と出るのですがどうしたらいいですか。教えてください。

専門家に質問してみよう