Xcode中的Boost库编译器错误

kmynzznz  于 2023-04-13  发布在  其他
关注(0)|答案(1)|浏览(178)

如何在Xcode中正确使用boost?
我尝试使用boost库编译一个项目。示例项目在终端中使用GCC 12编译得很好,但我无法让它在Xcode中编译。编译器错误主要是boost库中的命名空间问题。
例如:/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:11:11 No member named 'acos' in the global namespace .
在cmath文件中:

#ifndef __CMATH_HEADER
#define __CMATH_HEADER

#include <math.h>
namespace std {
using ::acos;
using ::cos;
using ::fmod;
using ::modf;
//...
}
#endif // CMATH_HEADER

我在OSX 12.6.1上工作,使用Xcode 14.2。包含路径设置为/usr/local/boost/boost_1_81_0。我尝试用C++20和C ++17编译。其他库包括cmath(不是来自boost)工作正常。
main.cpp中的示例项目:

#include <iostream>
#include <iterator>
#include <algorithm>

#include <boost/lambda/lambda.hpp>

int main()
{
    using namespace boost::lambda;
    typedef std::istream_iterator<int> in;
 
    std::for_each(
        in(std::cin), in(), std::cout << (_1 * 3) << " " );
}

编译器错误:

/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:11:11: error: no member named 'acos' in the global namespace
  using ::acos;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:12:11: error: no member named 'cos' in the global namespace
  using ::cos;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:13:11: error: no member named 'fmod' in the global namespace
  using ::fmod;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:14:11: error: no member named 'modf' in the global namespace
  using ::modf;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:15:11: error: no member named 'tan' in the global namespace
  using ::tan;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:16:11: error: no member named 'asin' in the global namespace
  using ::asin;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:17:11: error: no member named 'cosh' in the global namespace
  using ::cosh;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:18:11: error: no member named 'frexp' in the global namespace
  using ::frexp;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:19:11: error: no member named 'pow' in the global namespace
  using ::pow;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:20:11: error: no member named 'tanh' in the global namespace
  using ::tanh;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:21:11: error: no member named 'atan' in the global namespace
  using ::atan;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:22:11: error: no member named 'exp' in the global namespace
  using ::exp;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:23:11: error: no member named 'ldexp' in the global namespace
  using ::ldexp;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:24:11: error: no member named 'sin' in the global namespace
  using ::sin;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:25:11: error: no member named 'atan2' in the global namespace
  using ::atan2;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:26:11: error: no member named 'fabs' in the global namespace
  using ::fabs;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:27:11: error: no member named 'log' in the global namespace
  using ::log;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:28:11: error: no member named 'sinh' in the global namespace
  using ::sinh;
        ~~^
/usr/local/boost/boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:29:11: error: no member named 'ceil' in the global namespace
  using ::ceil;
        ~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
41ik7eoe

41ik7eoe1#

我不确定是什么解决了这个问题,但现在它工作了。我在Xcode中设置了头包含路径:/usr/local/boost/boost_1_81_0(非递归)。递归选项可能是所有错误的来源。感谢大家的帮助!

相关问题