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

Xcode错误:无法启动[目录]--无效的主机字符串:';本地主机';,xcode,string,localhost,launch,Xcode,String,Localhost,Launch,我试图在命令行工具中运行以下代码: #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); } return 0; } #导入 int main(int argc,const char*argv[] { @自动释放池{

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

#import <Foundation/Foundation.h>

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

    @autoreleasepool {

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

}
return 0;
}
#导入
int main(int argc,const char*argv[]
{
@自动释放池{
//在这里插入代码。。。
NSLog(@“你好,世界!”);
}
返回0;
}
在“构建成功”之后,我得到以下错误:

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


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

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

  • 您必须验证
    /etc/hosts
    文件中是否包含以下行
  • 执行
    dscacheutil-flushcache
    以重新加载DNS配置

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

Xcode error无效字符串localhost

开放式终端

//类型

sudo nano /etc/hosts
//它可以询问密码,输入密码

//复制并粘贴此文件

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0     localhost
然后按control-o,然后按enter,然后按control-x

//然后键入

  dscacheutil -flushcache 

< > >使用XCODE+C++,不使用互联网!p> 除了检查hosts文件中是否有正确的行之外,还要检查行尾是否为“Unix”,而不是其他类型的行尾。这就解决了我的问题。

修好了,打字。。。我正在编辑/etc/host而不是/etc/hosts(注意hosts末尾的“S”),谢谢!
  dscacheutil -flushcache