4

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

DimitrisA
  • 43
  • 1
  • 4

3 Answers3

11

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.

Sebastian Hojas
  • 4,158
  • 2
  • 27
  • 38
  • Got it fixed, typo... I was editing /etc/host instead of /etc/hosts (notice the "S" at the end of hosts) THANKS! – pec1985 May 03 '13 at 16:21
2

Xcode error Invalid string 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

//then type

  dscacheutil -flushcache 

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

0

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.