首页 > 解决方案 > 在 Linux 上编译没有问题时,如何在 Mac 上正确编译 C++?

问题描述

我正在使用其他人编写的在 Linux 上成功编译的 C++ 项目。在我将它克隆到 Mac 并执行“制作”后,它给出了这个错误:

clang: error: unknown argument: '-mpreferred-stack-boundary=4'
make: *** [all] Error 1

在我的 Mac 上,我安装了 g++。然后我从 Makefile 中删除 -mpreferred-stack-boundary=4 选项:

$(CC) $(CFLAGS) -mpreferred-stack-boundary=4 -mstackrealign  -o ${NAME}.so $(SEGSRC) $(CFILE) 

这些是 Makefile 中的一些定义:

CC                = /usr/bin/g++
CFLAGS    =   -D_ChaiScriptON -g -w -O0 -fPIC -shared -std=c++11

'c++11' 是否意味着我应该在我的 Mac 上安装 c++11?我已经安装了 g++。

我尝试从命令中删除 -mpreferred-stack-boundary=4 ,然后我给出了这个错误:

./CObjectRecognizer/include/commonsFun.h:15:10: fatal error: 'io.h' file not found
#include <io.h>
         ^~~~~~
1 error generated.

'io.h' 是否来自标准 c 库?

标签: c++cmacos

解决方案


C++11 is a version of C++. Unless your version of g++ is extremely old it will support C++11 without problems.

<io.h> is a non-standard header file. You should remove it, but unfortunately it's presence might mean that the code you are trying to compile is also non-standard. In which case you may have trouble getting the code to work in a different environment.

EDIT clang should have no trouble with C++11 either.


推荐阅读