如何正确使用boost与Xcode?
我正在尝试使用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.
我不确定是什么解决了这个问题,但它现在工作了。我将Xcode中的头包含路径设置为:/usr/local/boost/boost_1_81_0
(非递归)。递归选项可能是所有错误的根源。谢谢大家的帮助!