Search code examples
c++xcodeboost

Boost library compiler errors in Xcode


How do I correctly use boost with Xcode?

I'm trying to compile a project using the boost library. The example project compiles fine using GCC 12 in the terminal, but I can't get it to compile in Xcode. The compiler errors are mostly namespace problems within the boost library.
For example: /boost_1_81_0/boost/compatibility/cpp_c_headers/cmath:11:11 No member named 'acos' in the global namespace.
From that cmath file:

#ifndef __CMATH_HEADER
#define __CMATH_HEADER

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

I work on OSX 12.6.1 and use Xcode 14.2. The include paths are set to /usr/local/boost/boost_1_81_0. I tried to compile with C++20 and C++17. Other libraries including cmath (not from boost) work fine.

The example project in 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) << " " );
}

The compiler errors:

/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.

Solution

  • I'm not exactly sure what solved the problem, but it works now. I set the header include path in Xcode to: /usr/local/boost/boost_1_81_0 (non-recursive). The recursive option might have been the source of all the errors. Thanks everyone for the help!