调用包装的静态 c++ objc 库中的库导致链接器错误
我有一个 cpp 静态库,并尝试将其包装在静态 obj-c 库中,这样它从外部看起来就像一个普通的 obj-c 库。 我的 obj-c lib 编译得很好,但是当我尝试在应用程序中使用此库时,我收到以下链接器错误:
Apple Mach-O Linker (Id) Error
Undefined symbols for architecture i386:
"operator new(unsigned long)", referenced from:
...
所有库在每个所需的体系结构中都编译良好。
我的包装器库如下所示:
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();
}
在我的应用程序中,我在“链接二进制与库”下添加了 ObjcLib.a。此外,库搜索路径是正确的,但是当我尝试使用 [ObjcLib alloc] 创建对象时,我收到上述链接器错误。 我正在将 XCode4 与 LLVM 编译器 3.0 一起使用,
希望任何人都可以给我一个提示,说明可能出了什么问题,或者我的包装器是否正确。
编辑: 在应用程序的构建设置中添加 -lstdc++ 作为其他链接器标志可以解决很多链接器错误,但不是全部。解决的问题是 ObjcLib.h 和 ObjcLib.mm 中的 cpp 命令。剩下的是来自 BaseAPI 内部的一些方法调用。将仔细研究这一点,了解是什么使该方法调用与其他可以正确链接的方法调用不同。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不熟悉您的编译器或项目,但听起来标准库没有被链接。
-lstdc++
选项可以修复任何问题吗?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?