Project “app” gets build err: "Undefined symbol: run_mobile_session()"
Proj app includes ObjC class lib project hub_lib.
Proj hub_lib has folder with main.cpp file that has function "run_mobile_session()" that is undefined in app build
- I build without error the hub_lib project and did ctrl-drag of its .h and .a from its Xcode folders pane to a folder within project app.
- I dragged .h & .a from folder within app to folder pane of app. (ie. imported)
- I selected target to be my provisioned iPhone.
- Built app, got error.
I ran nm on and get this...
DOUGs-MacBook-Pro:mobile_sys_hub_lib dbell$ nm libmobile_sys_hub_lib.a | grep run_mobile_session
U __Z18run_mobile_sessionv
DOUGs-MacBook-Pro:mobile_sys_hub_lib
The U at the front of the line is "undefined". nm thinks you have a reference to the symbol but no implementation. – Phillip Mills
Doug: main.cpp seems to be getting compiled in the class lib: I put junk "zzzzzz" within run_mobile_session() and get build error.
THE CODE...
------------------------------------------- ObjC app project...
//app.h ...........................
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
// ViewController.mm ....................
#import <UIKit/UIKit.h>
#import "hub_lib.h"
@interface ViewController ()
@end
@implementation ViewController
. . .
- (IBAction)start_session:(id)sender
{
hub_lib* _lib = [hub_lib new];
NSLog(@"app: %d", [ _lib start_session]);
}
@end
--------------------------------------- lib project...
// hub_lib.h ....................
#import <Foundation/Foundation.h>
@interface hub_lib : NSObject
@end
// hub_lib.mm ......................................
#import "hub_lib.h"
#import <UIKit/UIKit.h>
@implementation hub_lib
extern void run_mobile_session(void);
. . .
-(int)start_session
{
run_mobile_session();
return 0;
}
@end
--------------------------------------- C++ folder within lib project...
// main.cpp .....................
#include <stdio.h>
void run_mobile_session(void);
. . .
void run_mobile_session(void)
{
. . .
}