简体   繁体   中英

Compiler error as clang: error: linker command failed with exit code 1 (use -v to see invocation) with completed app

I have created an app and completed successfully i just want to share in Fcebook and i tried by refering some tutorial. here is my code in viewcontroller.m file.

//
#import "ViewController.h"


@interface ViewController ()

@end

@implementation ViewController

@synthesize btnLogin;
@synthesize btnPublish;
@synthesize lblUser;
@synthesize actView;
@synthesize facebook;
@synthesize permissions;
@synthesize isConnected;

-(void)checkForPreviouslySavedAccessTokenInfo
{
// Initially set the isConnected value to NO.
isConnected = NO;

// Check if there is a previous access token key in the user defaults file.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"] &&
    [defaults objectForKey:@"FBExpirationDateKey"]) {
    facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
    facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];

    // Check if the facebook session is valid.
    // If it’s not valid clear any authorization and mark the status as not connected.
    if (![facebook isSessionValid]) {
        [facebook authorize:nil];
        isConnected = NO;
    }
    else {
        isConnected = YES;
    }
}
}


-(void)setLoginButtonImage{
UIImage *imgNormal;
UIImage *imgHighlighted;
UIImageView *tempImage;

// Check if the user is connected or not.
if (!isConnected) {
    // In case the user is not connected (logged in) show the appropriate
    // images for both normal and highlighted states.
    imgNormal = [UIImage imageNamed:@"LoginNormal.png"];
    imgHighlighted = [UIImage imageNamed:@"LoginPressed.png"];
}
else {
    imgNormal = [UIImage imageNamed:@"LogoutNormal.png"];
    imgHighlighted = [UIImage imageNamed:@"LogoutPressed.png"];
}

// Get the screen width to use it to center the login/logout button.
// We’ll use a temporary image view to get the appopriate width and height.
float screenWidth = [UIScreen mainScreen].bounds.size.width;    
tempImage = [[UIImageView alloc] initWithImage:imgNormal];
[btnLogin setFrame:CGRectMake(screenWidth / 2 - tempImage.frame.size.width / 2, btnLogin.frame.origin.y, tempImage.frame.size.width, tempImage.frame.size.height)];

// Set the button’s images.
[btnLogin setBackgroundImage:imgNormal forState:UIControlStateNormal];
[btnLogin setBackgroundImage:imgHighlighted forState:UIControlStateHighlighted];

// Release the temporary image view.
[tempImage  release];
}

-(void)showActivityView{
// Show an alert with a message without the buttons.
UIAlertView *msgAlert = [[UIAlertView alloc] initWithTitle:@"My test app" message:@"Please wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[msgAlert show];

// Show the activity view indicator.
actView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0, 0.0, 40.0, 40.0)];
[actView setCenter:CGPointMake(160.0, 350.0)];
[actView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:actView];
[actView startAnimating];
}


-(void)stopShowingActivity{
[actView stopAnimating];
UIAlertView *msgAlert = nil;
[UIAlertView:msgAlert dismissWithClickedButtonIndex:0 animated:YES];
}

-(void)saveAccessTokenKeyInfo{
// Save the access token key info into the user defaults.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}

-(void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response {
// Keep this just for testing purposes.
NSLog(@"received response");
}


-(void)request:(FBRequest *)request didLoad:(id)result{
// With this method we’ll get any Facebook response in the form of an array.
// In this example the method will be used twice. Once to get the user’s name to
// when showing the welcome message and next to get the ID of the published post.
// Inside the result array there the data is stored as a NSDictionary.    
if ([result isKindOfClass:[NSArray class]]) {
    // The first object in the result is the data dictionary.
    result = [result objectAtIndex:0];
}

// Check it the “first_name” is contained into the returned data.
if ([result objectForKey:@"first_name"]) {
    // If the current result contains the "first_name" key then it's the user's data that have been returned.
    // Change the lblUser label's text.
    [lblUser setText:[NSString stringWithFormat:@"Welcome %@!", [result objectForKey:@"first_name"]]];
    // Show the publish button.
    [btnPublish setHidden:NO];
}
else if ([result objectForKey:@"id"]) {
    // Stop showing the activity view.
    [self stopShowingActivity];

    // If the result contains the "id" key then the data have been posted and the id of the published post have been returned.
    UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"My test app" message:@"Your message has been posted on your wall!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    [al show];
    [al release];
}
}

-(void)request:(FBRequest *)request didFailWithError:(NSError *)error{
NSLog(@"%@", [error localizedDescription]);

// Stop the activity just in case there is a failure and the activity view is animating.
if ([actView isAnimating]) {
    [self stopShowingActivity];
}
}

-(void)fbDidLogin{
// Save the access token key info.
[self saveAccessTokenKeyInfo];

// Get the user's info.
[facebook requestWithGraphPath:@"me" andDelegate:self];
}

-(void)fbDidNotLogin:(BOOL)cancelled{
// Keep this for testing purposes.
//NSLog(@"Did not login");

UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"My test app" message:@"Login cancelled." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[al show];
}

-(void)fbDidLogout{
// Keep this for testing purposes.
//NSLog(@"Logged out");

// Hide the publish button.
[btnPublish setHidden:YES];
}

- (IBAction)LoginOrLogout {
// If the user is not connected (logged in) then connect.
// Otherwise logout.
if (!isConnected) {
    [facebook authorize:permissions];

    // Change the lblUser label's message.
    [lblUser setText:@"Please wait..."];
}
else {
    [facebook logout:self];
    [lblUser setText:@"Tap on the Login to connect to Facebook"];
}

isConnected = !isConnected;
[self setLoginButtonImage];
}

- (IBAction)Publish {
// Show the activity indicator.
[self showActivityView];

// Create the parameters dictionary that will keep the data that will be posted.
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"My test app", @"name",
                               @"http://www.google.com", @"link",
                               @"FBTestApp app for iPhone!", @"caption",
                               @"This is a description of my app", @"description",
                               @"Hello!\n\nThis is a test message\nfrom my test iPhone app!", @"message",              
                               nil];

// Publish.
// This is the most important method that you call. It does the actual job, the message posting.
[facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Set the permissions.
// Without specifying permissions the access to Facebook is imposibble.
permissions = [[NSArray arrayWithObjects:@"read_stream", @"publish_stream", nil] retain];

// Set the Facebook object we declared. We’ll use the declared object from the application
// delegate.
facebook = [[Facebook alloc] initWithAppId:@"236058923xxxxxx" andDelegate:self];

// Check if there is a stored access token.
[self checkForPreviouslySavedAccessTokenInfo];


// Depending on the access token existence set the appropriate image to the login button.
[self setLoginButtonImage];

// Specify the lblUser label's message depending on the isConnected value.
// If the access token not found and the user is not connected then prompt him/her to login.
if (!isConnected) {
    [lblUser setText:@"Tap on the Login to connect to Facebook"];
}
else {
    // Get the user's name from the Facebook account. The message will be set later.
    [facebook requestWithGraphPath:@"me" andDelegate:self];
}

// Initially hide the publish button.
[btnPublish setHidden:YES];

}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (void)dealloc {
[btnLogin release];
[lblUser release];
[btnPublish release];
[actView release];
[facebook release];
[permissions release];
[super dealloc];
}


@end

And the code in viewcontroller.h file is

#import <UIKit/UIKit.h>
#import "FBConnect.h"
#import "Facebook.h"

@interface ViewController : UIViewController <FBSessionDelegate, FBRequestDelegate,        FBDialogDelegate>{
UIButton *btnLogin;
UIButton *btnPublish;
UILabel *lblUser;
UIActivityIndicatorView *actView;

Facebook *facebook;

NSArray *permissions; 
BOOL isConnected;    

}

@property (retain, nonatomic) IBOutlet UIButton *btnLogin;
@property (retain, nonatomic) IBOutlet UIButton *btnPublish;
@property (retain, nonatomic) IBOutlet UILabel *lblUser;
@property (retain, nonatomic) UIActivityIndicatorView *actView;
@property (retain, nonatomic) Facebook *facebook;
@property (retain, nonatomic) NSArray *permissions;
@property (nonatomic) BOOL isConnected;
  • (IBAction)LoginOrLogout;
  • (IBAction)Publish;

    @end

Can anyone say y i'm getting these error.

EDIT:

from your comment, it seems that you also copied to your project the main.c file that comes with the Facebook SDK sample (or you might delete yours; main.c only contains boilerplate code). Remove it (or better, remove all the files related to the sample), and it should work.

My guess is you are not correctly linking your app with the Facebook framework, but you should really look into the exact error message you get from the compiler.

As to the first point, check this: Create your iOS project .

As to the second, in Xcode 4, click on the "Alert" icon like shown in the attached picture.

在此处输入图片说明

If you need more help, please report the exact error you get from the linker.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM