我正在尝试使用Makefile创建项目。 Makefile可以在其他Mac上正常工作,但在我的情况下会带来错误。

输出如下:

CC  kernel.cpp
In file included from kernel.cpp:13:
In file included from ./kernel.hpp:22:
In file included from /usr/local/include/Poco/JSON/Object.h:24:
In file included from /usr/local/include/Poco/JSON/Array.h:25:
In file included from /usr/local/include/Poco/Dynamic/Var.h:26:
In file included from /usr/local/include/Poco/Dynamic/VarHolder.h:24:
In file included from /usr/local/include/Poco/NumberFormatter.h:24:
In file included from /usr/local/include/Poco/NumericString.h:25:
In file included from /usr/local/include/Poco/FPEnvironment.h:35:
In file included from /usr/local/include/Poco/FPEnvironment_C99.h:25:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:313:9: error:
      no member named 'signbit' in the global namespace
using ::signbit;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:314:9: error:
      no member named 'fpclassify' in the global namespace
using ::fpclassify;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:315:9: error:
      no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
      ~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/math.h:757:12: note:
      'finite' declared here
extern int finite(double) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __M...
           ^
In file included from kernel.cpp:13:
In file included from ./kernel.hpp:22:
In file included from /usr/local/include/Poco/JSON/Object.h:24:
In file included from /usr/local/include/Poco/JSON/Array.h:25:
In file included from /usr/local/include/Poco/Dynamic/Var.h:26:
In file included from /usr/local/include/Poco/Dynamic/VarHolder.h:24:
In file included from /usr/local/include/Poco/NumberFormatter.h:24:
In file included from /usr/local/include/Poco/NumericString.h:25:
In file included from /usr/local/include/Poco/FPEnvironment.h:35:
In file included from /usr/local/include/Poco/FPEnvironment_C99.h:25:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:316:9: error:
      no member named 'isinf' in the global namespace
using ::isinf;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:317:9: error:
      no member named 'isnan' in the global namespace
using ::isnan;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:318:9: error:
      no member named 'isnormal' in the global namespace
using ::isnormal;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:319:7: error:
      no member named 'isgreater' in the global namespace; did you mean
      '::std::greater'?
using ::isgreater;
      ^~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/functional:718:29: note:
      '::std::greater' declared here
struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
                            ^
In file included from kernel.cpp:13:
In file included from ./kernel.hpp:22:
In file included from /usr/local/include/Poco/JSON/Object.h:24:
In file included from /usr/local/include/Poco/JSON/Array.h:25:
In file included from /usr/local/include/Poco/Dynamic/Var.h:26:
In file included from /usr/local/include/Poco/Dynamic/VarHolder.h:24:
In file included from /usr/local/include/Poco/NumberFormatter.h:24:
In file included from /usr/local/include/Poco/NumericString.h:25:
In file included from /usr/local/include/Poco/FPEnvironment.h:35:
In file included from /usr/local/include/Poco/FPEnvironment_C99.h:25:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:320:7: error:
      no member named 'isgreaterequal' in the global namespace; did you mean
      '::std::greater_equal'?
using ::isgreaterequal;
      ^~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/functional:747:29: note:
      '::std::greater_equal' declared here
struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
                            ^

该makefile已在Linux平台上经过测试,并且可以正常工作。
有什么建议,我的Mac c++配置有什么问题?

我正在使用MacOS High Sierra(10.13)和Xcode v9.0.1

编辑

这是编译命令:
gcc -pipe -x c++ -std=c++11 -fPIC -pedantic -W -Wall -Wwrite-strings -Wcast-align -Wcast-qual -Wpointer-arith -Wshadow -Wendif-labels -Wundef -Wfloat-equal -Werror -Wconversion -DPROJECT_VERSION="0.0.1" -DUSE_SDK="no"  -g -g3 -ggdb3 -D__i386__=1 -D__ppc64__=0 -Wno-sign-conversion -Wno-conversion -Wno-float-equal -Wno-unused-parameter -I/usr/local/include -I/usr/local/opt/openssl/include  -I/usr/local/include -I/usr/local/opt/openssl/include  -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/c++/version -I/git/p2p/inc -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/c++/version  src/kernel.cpp -o /git/p2p/obj/kernel.o

最佳答案

建议您不要运行gcc -x c++,而最好在MacOS上运行g++,而不是clang++

另外,您的编译行似乎缺少-c选项,该选项将告诉编译器生成目标文件。否则,它将尝试链接文件并创建可执行文件。

同样,我发现将-D__i386__-D__ppc64__添加到编译行中也很奇怪:这些通常是操作系统定义的系统宏,未在编译器的命令行上提供。

另一个潜在的问题是,为什么要使用-I将系统头文件目录显式添加到编译行中。编译器将自己添加这些,并使用适当的配置。系统标题通常需要格外小心,以正确的顺序包括在内。

如果更改到正确的目录并从 shell 程序提示符运行此目录:

clang++ -pipe -std=c++11 -fPIC -pedantic -W -Wall -Wwrite-strings \
  -Wcast-align -Wcast-qual -Wpointer-arith -Wshadow -Wendif-labels \
  -Wundef -Wfloat-equal -Werror -Wconversion -DPROJECT_VERSION="0.0.1" \
  -DUSE_SDK="no"  -g -g3 -ggdb3 -Wno-sign-conversion -Wno-conversion \
  -Wno-float-equal -Wno-unused-parameter -I/usr/local/include \
  -I/usr/local/opt/openssl/include -I/git/p2p/inc \
  -c -o /git/p2p/obj/kernel.o  src/kernel.cpp

它可以正确编译吗?

关于c++ - 在Mac上失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47018913/

10-09 18:40