我需要一些编译错误的帮助。整个计划如下:
int main(int argc, char* argv[])
{
NSLog("entered main\n");
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://YourURL.com/FakeURL/PARAMETERS"]];
[request setHTTPMethod:@"GET"];
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"requestReply: %@", requestReply);
}] resume];
NSLog("leaving main\n");
return 0;
}
这是我在Objective-C中编程的第二天。所有我都想尝试从Objective-C做出GET请求。这是在OSX上使用gcc。我安装了xcode,但这是一个简单的程序。编译器抱怨:
Undefined symbols for architecture x86_64:
"_NSLog", referenced from:
___23-[Easyhttp sendHTTPGet]_block_invoke in Easyhttp-c1cd8d.o
"_OBJC_CLASS_$_NSOperationQueue", referenced from:
objc-class-ref in Easyhttp-c1cd8d.o
"_OBJC_CLASS_$_NSString", referenced from:
objc-class-ref in Easyhttp-c1cd8d.o
"_OBJC_CLASS_$_NSURL", referenced from:
objc-class-ref in Easyhttp-c1cd8d.o
"_OBJC_CLASS_$_NSURLSession", referenced from:
objc-class-ref in Easyhttp-c1cd8d.o
"_OBJC_CLASS_$_NSURLSessionConfiguration", referenced from:
objc-class-ref in Easyhttp-c1cd8d.o
"___CFConstantStringClassReference", referenced from:
CFString in Easyhttp-c1cd8d.o
CFString in Easyhttp-c1cd8d.o
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
答案 0 :(得分:0)
您正在使用的那些类是Foundation框架(NSString,NSLog等)的一部分。您需要将其导入到您的代码中。