【发布时间】:2020-07-09 18:54:10
【问题描述】:
我正在创建一个示例静态库以在我的 iOS 应用程序中使用,但是,在调用静态库的方法时,我遇到了链接器错误:
Undefined symbols for architecture arm64:
"_doMath", referenced from:
_doMathInterface in libTestMain.a(Test.o)
(maybe you meant: _doMathInterface)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是静态库的结构:
我有一个头文件Test.h:
#import <Foundation/Foundation.h>
@interface Test : NSObject
int doMathInterface(int a, int b);
@end
及其实现Test.m:
#import "Test.h"
#include "PaymentAPI.h"
@implementation Test
int doMathInterface(int a, int b){
return doMath(a, b);
}
@end
在 PaymentAPI.h 中:
#ifndef PaymentAPI_h
#define PaymentAPI_h
int doMath(int a, int b);
#endif /* PaymentAPI_h */
终于在 PaymentAPI.cpp 中:
#include <stdio.h>
#include "PaymentAPI.h"
int doMath(int a, int b){
return a + b;
}
正如您所见,它是一个非常简单的静态库,但我无法弄清楚为什么会发生此链接器错误,我已在应用程序的 Build Phases 的“Link Binaries with Libraries”中添加了静态库。
这是应用文件的截图:
我相信构建设置中的搜索路径配置也是正确的:
这是静态库项目的一些构建设置的屏幕截图
非常感谢。
【问题讨论】:
标签: c++ ios xcode static-libraries