我正在创建一个样例静态库,用于我的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;
}
你可以看到这是一个非常简单的静态库,但我无法找出为什么会出现链接器错误,我已经在应用程序的“Link Binaries with Libraries”中添加了静态库。
以下是应用程序文件的截图:
而且构建设置中的搜索路径配置也是正确的:
以下是一些静态库项目的构建设置截图:
非常感谢。