Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'

any solution??? Thank you

like image 270
DimitrisA Avatar asked Dec 13 '22 04:12

DimitrisA


1 Answers

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/hosts file
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0     localhost
  • Execute dscacheutil -flushcache to reload the DNS configuration

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.

like image 109
Sebastian Hojas Avatar answered Dec 15 '22 01:12

Sebastian Hojas