-1

我写了一个test.cpp:

      #include <iostream>
      #include <stack>
      #include <boost/lexical_cast.hpp>
      #include <boost/config/warning_disable.hpp>
      #include <boost/spirit/include/qi.hpp>
      #include <boost/spirit/include/phoenix.hpp>

      using namespace std;
      namespace phoenix = boost::phoenix;
      namespace qi = boost::spirit::qi;
      namespace ascii = boost::spirit::ascii;

     struct calculator
     {
      bool interpret(const string& s);
      void do_neg();
      void do_add();
       void do_sub();
      void do_mul();
        void do_div();
        void do_number(const char* first, const char* last);
          int val() const;
      private:
      stack<int> values_;
      int *pn1_, n2_;
      void pop_1();
      void pop_2();
      };
     ......................
     ....................

但是当我使用 g++ test.cpp -o test 时,会出现类似的错误boost/lexical_cast.hpp: No such file or directory,但是我已经将 boost 中的所有文件(从 boost.org 下载)复制到 test.cpp 文件夹,如何让 g++ 知道标头路径?谢谢

我用了g++ test.cpp -o test

使用" "是不可能的,我有很多头文件的依赖。

4

1 回答 1

1

您必须确保将包含修改为 g++ 的命令。从手册页阅读(这是你最好的朋友):

Add the directory dir to the list of directories to be searched for
header files.  Directories named by -I are searched before the
standard system include directories.  If the directory dir is a
standard system include directory, the option is ignored to ensure
that the default search order for system directories and the
special treatment of system headers are not defeated .  If dir
begins with "=", then the "=" will be replaced by the sysroot
prefix; see --sysroot and -isysroot.

对您而言,命令应如下所示:

g++ -I path/to/boost test.cpp
于 2012-09-25T17:46:18.507 回答