Xcode 错误:无法启动 [目录] -- 无效的主机字符串:'localhost'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9832234/
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-14 23:45:48  来源:igfitidea点击:

Xcode error: failed to launch [directory] -- invalid host string: 'localhost'

xcodestringlocalhostlaunch

提问by DimitrisA

I am trying to run in command line tool the following code:

我正在尝试在命令行工具中运行以下代码:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

    @autoreleasepool {

       // insert code here...
    NSLog(@"Hello, World!");

}
return 0;
}

and after "Build Succeeded" I am getting the following error:

在“构建成功”之后,我收到以下错误:

error: failed to launch '/Users/dimitrisagagiotis/Library/Developer/Xcode/DerivedData/test-guvgymeaqzlsheascqbmllxdtpsn/Build/Products/Debug/test' -- invalid host string: 'localhost'

错误:无法启动“/Users/dimitrisagagiotis/Library/Developer/Xcode/DerivedData/test-guvgymeaqzlsheascqbmllxdtpsn/Build/Products/Debug/test”——无效的主机字符串:“localhost”

any solution??? Thank you

有什么解决办法???谢谢

回答by Sebastian Hojas

I had the same issue and resolved it with the following steps.

我遇到了同样的问题,并通过以下步骤解决了它。

  • You have to verify that the following lines are included in the /etc/hostsfile
  • 您必须验证以下行是否包含在/etc/hosts文件中
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0     localhost
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0     localhost
  • Execute dscacheutil -flushcacheto reload the DNS configuration
  • 执行dscacheutil -flushcache以重新加载 DNS 配置

I have absolutely no idea how it was possible to get a host file without the loopback DNS entries to localhost. From this point of view, "invalid host string: 'localhost'"is pretty self-describing: localhost is a invalid host string to the system, it simply can not resolve localhost.

我完全不知道如何在没有到本地主机的回送 DNS 条目的情况下获取主机文件。从这个角度来看,“无效的主机字符串:'localhost'”是非常自我描述的:localhost 对系统来说是一个无效的主机字符串,它根本无法解析 localhost。

回答by Sriharsha Sammeta

Xcode error Invalid string localhost

Xcode 错误无效字符串 localhost

open terminal

打开终端

//type

//类型

sudo nano /etc/hosts

// it may ask for password , enter the password;

// 可能会要求输入密码,输入密码;

// copy and paste this

// 复制并粘贴这个

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0     localhost

then press control-o and then press enter and then press control-x

然后按 control-o 然后按 enter 然后按 control-x

//then type

//然后输入

  dscacheutil -flushcache 

//use Xcode for c & c++ without internet !

//在没有互联网的情况下使用 Xcode for c & c++ !

回答by plobnop

In addition to checking that the correct lines are in the hosts file check that line endings are "Unix" and not some other kind of line ending. This solved the problem for me.

除了检查主机文件中的行是否正确之外,还要检查行结尾是否为“Unix”而不是其他类型的行结尾。这为我解决了这个问题。