我需要在ViewController中使用C ++单例,并且出错。
TradeAPIManager.h
#include <stdio.h>
class TradeAPIManager{
public:
static TradeAPIManager * getInstance();
void test();
private:
TradeAPIManager(){}
static TradeAPIManager *m_pInstance;
};
TradeAPIManager.cpp
#include "TradeAPIManager.h"
TradeAPIManager *TradeAPIManager::m_pInstance = nullptr;
TradeAPIManager *TradeAPIManager::getInstance(){
if(m_pInstance == nullptr){
m_pInstance = new TradeAPIManager();
}
return m_pInstance;
}
void test(){
printf("asdasd");
}
ViewController.mm
- (void)viewDidLoad {
[super viewDidLoad];
TradeAPIManager *manager = TradeAPIManager::getInstance();
manager->test();
}
构建时,我得到这样的错误:
Undefined symbols for architecture x86_64:
"TradeAPIManager::test()", referenced from:
-[ViewController viewDidLoad] in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
模拟器中架构x86_64的未定义符号
我的iPhone中架构arm64的未定义符号
那不是.a lib或框架,只是我自己编写的cpp文件 我尝试了六个小时但没有出路。 希望有人能提供帮助 非常感谢