xcode Mac OSX - 在优胜美地更新后在每个 C++ 程序(甚至 Hello World)上出现分段错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26563079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:59:56  来源:igfitidea点击:

Mac OSX - Getting Segmentation Faults on every C++ Program (Even Hello World) after Yosemite Update

c++xcodemacososx-yosemite

提问by carbon_ghost

I recently just upgraded to OSX Yosemite on my Mac and while I'm not sure if this is the cause, it does seem suspicious that suddenly all of My C++ Programs throw a Segmentation Fault.

我最近刚刚在我的 Mac 上升级到 OSX Yosemite,虽然我不确定这是否是原因,但我的所有 C++ 程序突然抛出一个分段错误似乎很可疑。

I even tried the basic of all basic "Hello World" programs and I still get a Segmentation Fault. Literally, every single C++ program does the same.

我什至尝试了所有基本的“Hello World”程序的基础,但仍然出现分段错误。从字面上看,每个 C++ 程序都做同样的事情。

#include <iostream>

using namespace std;

int main()
{
   cout << "Hello World" << endl;
}

I installed the Xcode updates to see if that would remedy the situation but no luck. I'm curious, is anyone else out there having the same problem? Regardless of Yosemite, have you had this problem where your Mac throws Segmentation faults for everything?

我安装了 Xcode 更新,看看这是否能解决这种情况,但没有运气。我很好奇,有没有其他人遇到同样的问题?不管优胜美地,你有过这样的问题,在你的Mac抛出分段错误的一切

I should add, I'm compiling with g++

我应该补充一下,我正在用 g++ 编译

回答by Salvatore Rappoccio

After a few more tries I have found a workaround from here:

经过几次尝试后,我从这里找到了一个解决方法:

http://lists.gnu.org/archive/html/libtool-patches/2014-09/msg00002.html

http://lists.gnu.org/archive/html/libtool-patches/2014-09/msg00002.html

Simply

简单地

setenv MACOSX_DEPLOYMENT_TARGET 10.9

or

或者

export MACOSX_DEPLOYMENT_TARGET=10.9

Happily works after that. However, proper bug fixes should be forthcoming from libtool, so watch the progress there.

在那之后愉快地工作。但是,libtool 应该会提供适当的错误修复,因此请注意那里的进度。

回答by Ahmed Nawar

My g++ version is (MacPorts gcc47 4.7.4_5+universal) 4.7.4

我的 g++ 版本是 (MacPorts gcc47 4.7.4_5+universal) 4.7.4

I ran sudo port selfupdatefollowed by sudo port upgrade outdated

sudo port selfupdate跟着跑 sudo port upgrade outdated

This worked for me

这对我有用

also you can run launchctl setenv MACOSX_DEPLOYMENT_TARGET 10.9to make it permanent.

您也可以运行launchctl setenv MACOSX_DEPLOYMENT_TARGET 10.9以使其永久化。