0

次のコードは、現在の作業パスを処理します。ブースト 1.52 を使用し、ビジュアル スタジオ 2010 で動作します。

#include <iostream>
#include <string>
#include "boost/algorithm/string.hpp"
#include "boost/filesystem/path.hpp"
#include "boost/filesystem/operations.hpp"
#include "boost/format.hpp"

int main(int argc, const char* argv[]) {
        std::string p = boost::filesystem::initial_path<boost::filesystem::path>().string();
        std::cout << p;
        return 0;
}

ただし、Linux では、コンパイルに失敗すると、エラー メッセージが表示されます。

g++ -g -I/root/boost_1_52_0 -c main.cpp -o main.o
main.cpp: In function ‘int main(int, const char**)’:
main.cpp:9: error: expected primary-expression before ‘&gt;’ token
main.cpp:9: error: expected primary-expression before ‘)’ token
make: *** [main.o] Error 1

stackoverflow で同じエラーの投稿を検索しましたが、修正方法がわかりませんでした。どんな助けでも大歓迎です。

g++ バージョン:

Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --disable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)

------------------- 問題修正 ------------------------

問題を解決します。理由は、boost ヘッダー ファイルのディレクトリ名を変更し、同時に makefile のインクルード パスを変更するのを忘れたためです。

後で、エラーに遭遇します:

boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()

これは、コンパイルしたブースト ライブラリを他の場所からコピーしたことが原因です。理由によっては、私の Linux と互換性がありません。ブーストを再コンパイルしましたが、最終的にはすべて動作します。

doctorlove、Igor R、levengli、cv_and_he の助けに感謝します!

4

0 に答える 0