Search code examples
iosobjective-clinker-errorsmessageui

What is this linker error telling me?


I am trying to get a basic sample of in-app email working, and getting a linker error which seems to relate to the MessageUI framework. IN my .h file I have

 #import <UIKit/UIKit.h>
 #import <MessageUI/MessageUI.h>

 @interface ButtonViewController : UIViewController
 <MFMailComposeViewControllerDelegate>
 {
        MFMailComposeViewController *mailComposer;
 }

and in my .m file I use that mailComposer object. I alloc init it and set it, without compiler errors.

 mailComposer =[[MFMailComposeViewController alloc] init];
 mailComposer.mailComposeDelegate = self;
 [mailComposer setSubject:@"Test mail"];
 [mailComposer setMessageBody:@"Testing Message Body" isHTML:NO];

 [self presentViewController:mailComposer animated:YES completion:nil];

But I do get linker errors. I think I'm missing something I need to do up front.

Undefined symbols for architecture i386:
"_OBJC_CLASS_$_MFMailComposeViewController", referenced from:
  objc-class-ref in ButtonViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(null): "_OBJC_CLASS_$_MFMailComposeViewController", referenced from:

(null): Objc-class-ref in ButtonViewController.o

(null): Symbol(s) not found for architecture i386

(null): Linker command failed with exit code 1 (use -v to see invocation)

Thank you. Laurel


Solution

  • You need to link MessageUI framework.
    Go to your project settings, select correct target -> general, scroll down to "linked frameworks and libraries" press + and add MessageUI.framework