c++ - g++ 不能在 Mac OS X Mavericks 上编译

标签 c++ macos g++ osx-mavericks

我的新 MacBook 和 Mac OS X Mavericks 有点问题。 在我的 Linux 机器上,我的代码编译没有问题,但在我的 Mac 上,我收到我不理解的神秘错误消息。

例如这样的事情:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/list:240:62: error: 
  invalid use of non-static data member '__ptr_'
explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}

有人可以帮帮我吗?我真的不知道该怎么办...

编辑: 所以...这是错误日志中的更多信息。这是第一部分。完整的日志太长了...

g++ SpinDerivatorController.cpp functions.cpp globalVariables.cpp main.cpp mathFunctions.cpp svd.cpp -o testCompile
In file included from SpinDerivatorController.cpp:8:
In file included from ./SpinDerivatorController.h:11:
In file included from ./SpinOperators.h:11:
In file included from ./SpinStateTemplate.h:11:
In file included from ./StateTemplateSimple.h:19:
./SeriesTemplate.h:217:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
 ./SeriesTemplate.h:314:4: note: in instantiation of member function      'SeriesTemplate<std::__1::complex<double>,
  ExponentsTemplate<int> >::operator*=' requested here
    s3*=s2;
      ^
./StateTemplateSimple.h:444:25: note: in instantiation of function template specialization
  'operator*<std::__1::complex<double>, ExponentsTemplate<int> >' requested here
                                    x += (it1->second) * (it2->second);
                                                       ^
 SpinDerivatorController.cpp:127:24: note: in instantiation of function template specialization
  'operator*<SeriesTemplate<std::__1::complex<double>, ExponentsTemplate<int> > >' requested here
                    b[k]=(inputStates[j]*outputStates[i]).real();
                                        ^
1 warning generated.
In file included from functions.cpp:8:
In file included from ./functions.h:15:
In file included from ./StateTemplateSimple.h:12:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/list:240:62: error: 
  invalid use of non-static data member '__ptr_'
explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
                                                         ^~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/list:240:69: error: 
  use of undeclared identifier '__p'
explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
                                                                ^
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/list:240:60: error: 
  C++ requires a type specifier for all declarations
explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
                                                       ^
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/list:245:21: error: 
  expected member name or ';' after declaration specifiers
template<class, class> friend class list;
                ^
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/list:245:21: error: 
  C++ requires a type specifier for all declarations
template<class, class> friend class list;
                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/list:245:20: error: 
  expected ';' at end of declaration list
template<class, class> friend class list;
               ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/list:263:5: error: 
  expected member name or ';' after declaration specifiers
{
^
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/list:240:50: error: 
  expected expression
explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
                                             ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/__config:289:21: note: 
  expanded from macro '_NOEXCEPT'
#  define _NOEXCEPT throw()
                ^
./nr3.h:71:59: note: expanded from macro 'throw'
 {printf("ERROR: %s\n     in file %s at line %d\n", message,__FILE__,__LINE__); throw(1);}

最佳答案

您在第 71 行的 nr3.h定义一个名为 throw 的宏。这与 throw< 的使用冲突 C++ 标准库中的关键字。

一个简单的解决方案是将宏命名为其他名称,例如 MY_PROJECT_THROW

无论如何,最好为您定义的所有宏添加一个唯一字符串前缀,以防止此类名称冲突。

关于c++ - g++ 不能在 Mac OS X Mavericks 上编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21609598/

相关文章:

macos - 剪裁时打印像素化

c++ - C++ 中的彩色输出

linux - windows-linux g++ 编译器内存错误

java - 从 C++ 调用非静态 java 方法时 JNI 访问冲突

c++ - 指向组合接口(interface)的指针 - 指向实现一个接口(interface)并从另一个接口(interface)的实现扩展的类

objective-c - 开发一个在用户使用 xcode 登录之前运行的 osx 守护进程

c++ - IDE如何从头文件.h中找到共享库名.so

c++ - 如何分析固件镜像的大小?

C++/C语言独立内存分配

c++ - std::stringstream 和 std::ios::binary