简体   繁体   中英

Call of a wrapped static c++ library in an objc library causes linker error

I have a cpp static library and tried to wrap this in a static obj-c library so that it looks from the outside like a normal obj-c lib. My obj-c lib compiles fine, but when i try to use this lib in an App I get the following Linker error:

Apple Mach-O Linker (Id) Error
Undefined symbols for architecture i386:
  "operator new(unsigned long)", referenced from:
...

All libs compile fine in every needed architecture.

My wrapper lib looks like this:

ObjcLib.h

@interface  ObjcLib: NSObject{
}
- (void) doSomething:(NSString*)text;
@end

ObjcLib.mm

#import "ObjcLib.h"
#import "apiFromCppLib.h"
@interface ObjcLib (){
@private
    cppApiNamespace::BaseApi* api;
}
@end

@implementation ObjcLib
- (void) doSomething:(NSString*)text{
    api = new cppApiNamespace::BaseAPI();
}

In my App I added ObjcLib.a under Link Binary With Libraries. Also the Library Search Path is correct, but when i try to create an object with [ObjcLib alloc] I get the above mentioned Linker Error. I am Using XCode4 with the LLVM Compiler 3.0

Hope anyone can give me an hint what could be wrong or if my wrapper is even right.

EDIT: adding -lstdc++ as an Other Linker Flag in the Build Settings of the App solves a lot of the Linker errors but not all. Thoses which were solved were cpp commands in ObjcLib.h and ObjcLib.mm. Thoses who remain are some method calls from within the BaseAPI. Will have a closer look to this, about what makes this method calls different from those others which could linked correctly.

I'm not familiar with your compiler or project but it sounds like the standard library isn't being linked. Does a -lstdc++ option fix anything?

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