我在这里遇到了一个奇怪的问题,我正在尝试将libkml C++ 项目源集成到我的 iOS 项目中。该项目可以独立编译,但是在通过这行代码进行链接时:
kmldom::PointPtr appPoint = kmlconvenience::CreatePointLatLon(appLocation.coordinate.latitude, appLocation.coordinate.longitude);
只有当我为模拟器构建它时,我才会收到链接器错误。当我为 iOS 设备构建它时它工作正常,但对于模拟器我得到以下 3 个链接器错误:
(null): "kmldom::GxTimeSpan::GxTimeSpan()", referenced from:
(null): Kmldom::KmlFactory::CreateGxTimeSpan() const in libLibKML.a(kml_factory.o)
(null): "kmldom::GxTimeStamp::GxTimeStamp()", referenced from:
(null): Kmldom::KmlFactory::CreateGxTimeStamp() const in libLibKML.a(kml_factory.o)
(null): Symbol(s) not found for architecture i386
(null): Linker command failed with exit code 1 (use -v to see invocation)
我可以单独为设备开发,但我希望解决这个问题有两个原因:
- 团队有时很容易将模拟器用于开发目的。
- 我真的很想深入了解它并了解为什么在第一种情况下会发生这种情况。为什么它为设备构建而为模拟器失败,尽管目标相同并且目标中包含的源文件在模拟器和设备之间是相同的?
GXTimeStamp 和 GXTimeSpan 类的定义在头文件 gx_timeprimitive.h 中,内容如下:
#ifndef KML_DOM_GX_TIMEPRIMITIVE_H__
#define KML_DOM_GX_TIMEPRIMITIVE_H__
#include <string>
#include "kml/base/xml_namespaces.h"
#include "kml/dom/kml22.h"
#include "kml/dom/object.h"
#include "kml/dom/timeprimitive.h"
namespace kmldom {
class Serializer;
class Visitor;
// <gx:TimeSpan>
class GxTimeSpan : public TimeSpan {
public:
virtual ~GxTimeSpan();
static KmlDomType ElementType() {
return Type_GxTimeSpan;
}
virtual KmlDomType Type() const { return Type_GxTimeSpan; }
virtual bool IsA(KmlDomType type) const {
return type == Type_GxTimeSpan || TimeSpan::IsA(type);
}
// Visitor API methods, see visitor.h.
virtual void Accept(Visitor* visitor);
private:
friend class KmlFactory;
GxTimeSpan();
LIBKML_DISALLOW_EVIL_CONSTRUCTORS(GxTimeSpan);
};
// <gx:TimeStamp>
class GxTimeStamp : public TimeStamp {
public:
virtual ~GxTimeStamp();
static KmlDomType ElementType() {
return Type_GxTimeStamp;
}
virtual KmlDomType Type() const { return Type_GxTimeStamp; }
virtual bool IsA(KmlDomType type) const {
return type == Type_GxTimeStamp || TimeStamp::IsA(type);
}
// Visitor API methods, see visitor.h.
virtual void Accept(Visitor* visitor);
private:
friend class KmlFactory;
GxTimeStamp();
LIBKML_DISALLOW_EVIL_CONSTRUCTORS(GxTimeStamp);
};
} // end namespace kmldom
#endif // KML_DOM_GX_TIMEPRIMITIVE_H__
我读过很多帖子,因为源文件没有编译,所以会发生链接器错误。我也在考虑同样的问题来解决这个问题,但是我不能将此头文件包含到编译源中,因为它是一个 .h 文件。
另外,我仔细检查了 - kml_factory.cc 文件包含在内部项目的编译源中:
期待建议和帮助。谢谢。