编译c ++时,体系结构x86_64的未定义符号

时间:2012-05-02 20:55:06

标签: c++ compiler-errors

我不断得到那个错误,这让我发疯了!

Undefined symbols for architecture x86_64:
  "SSResourcesDepot::_sharedInstance", referenced from:
    SSResourcesDepot::sharedInstance() in SSResourcesDepot.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我的代码如下:

#ifndef SolarSystem_SSResourcesDepot_h
#define SolarSystem_SSResourcesDepot_h
#include "SSResource.h"

/* SSResourcesDepot is implemented as a Singleton Depot that keeps track of all
 * requested Resource objects, and avoid loading them twice in memory. */
class SSResourcesDepot {

    SSResourcesDepot() {};
    SSResourcesDepot(SSResourcesDepot const&){};
    SSResourcesDepot& operator=(SSResourcesDepot const&){};

    static SSResourcesDepot* _sharedInstance;

    SSResource* _search(std::string resourceName);
    SSResource* _load(std::string resourceName);

public:
    static SSResourcesDepot* sharedInstance();
    SSResource* requestResource(std::string resourceName);

};

#endif

#include <iostream>
#include "SSResourcesDepot.h"


#pragma mark Public methods
SSResourcesDepot* SSResourcesDepot::sharedInstance() {
    if (SSResourcesDepot::_sharedInstance == 0) {
        SSResourcesDepot::_sharedInstance = new SSResourcesDepot();
    }
    return SSResourcesDepot::_sharedInstance;
}

SSResource* SSResourcesDepot::requestResource(std::string resourceName) {
    SSResource *resource = this->_search(resourceName);
    if (resource == NULL) resource = this->_load(resourceName);
    return resource;
}


#pragma mark Private methods
SSResource* SSResourcesDepot::_search(std::string resourceName) {
    return NULL;
}

SSResource* SSResourcesDepot::_load(std::string resourceName) {
    return NULL;
}

这对我来说似乎完全有用,但Apple-O-Matcher一直在抱怨,它不让我编译......:-S

提前致谢!

1 个答案:

答案 0 :(得分:1)

您没有初始化static成员。

添加

SSResourcesDepot* SSResourcesDepot::_sharedInstance = NULL;

到您的实施文件。