1

I have a swift project that depends on an objective-c++ static lib. When I compile the static lib alone, there is no error. But when I add the lib as a sub project to a swift project and compile it, I got the following error:

Undefined symbols for architecture x86_64: "___gxx_personality_v0", referenced from: +[obj_photo open] in libphoto.a(photo.o) Dwarf Exception Unwind Info (__eh_frame) in libphoto.a(photo.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

The objective-c++ file looks like this

// -- Obj-C++, photo.mm
#include "photo.hpp"
#import "photo.h"
#import <UIKit/UIKit.h>
#import <Photos/Photos.h>
#import <Photos/PHAsset.h>
#import <Photos/PHFetchOptions.h>

@implementation obj_photo
+ ( bool )open
{
    PHFetchOptions *options = [[PHFetchOptions alloc] init];
    PHFetchResult *fetchResult = [PHAsset fetchAssetsWithOptions:options];
    return true;
}
@end

bool photo::open_photo()
{
    return [obj_photo open ];
}

And in the swift file, I called the open_photo()

The weird thing is if I remove the following line:

PHFetchResult *fetchResult = [PHAsset fetchAssetsWithOptions:options];

I don't get the link error.

Any clues?

jiawen
  • 1,198
  • 2
  • 17
  • 29
  • Just add `-lstdc++` or `-lc++` to the compiler options and it should work (I'm not sure which C++ library you are using, so you should try both options). – paulotorrens Aug 11 '15 at 01:42
  • 1
    adding -lstdc++ to the Other Linker Flags in the swift project solved the problem. – jiawen Aug 11 '15 at 23:54

0 Answers0