我在Qt
1中有两个模块。SapPackets:lib
2. SapApplication:
两个模块的
SapApplication应用程序文件SapPackets.pro具有
Qt- = gui SapApplication.pro具有Qt + =核心gui xml
目标操作系统是Windows 7
#ifndef SAPENTITYCLASS_HPP
#define SAPENTITYCLASS_HPP
#include <QString>
namespace Sap
{
namespace Entity
{
class SapEntityClass
{
protected:
unsigned short mush_Id; /* Entity Id */
QString msz_title; /* Entity Title */
public:
SapEntityClass(const unsigned short Id,const QString title);
unsigned short GetId() const;
QString GetTitle() const;
};
}
}
#endif
#include "SapEntityClass.hpp"
using namespace Sap::Entity;
SapEntityClass::SapEntityClass(const unsigned short Id,const QString title)
:mush_Id(Id),msz_title(title)
{}
inline
unsigned short SapEntityClass::GetId() const
{
return mush_Id;
}
inline
QString SapEntityClass::GetTitle() const
{
return msz_title;
}
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../SapPackets_Build/release/ - lSapPackets
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../SapPackets_Build/debug/ -lSapPackets
else:unix: LIBS += -L$$PWD/../SapPackets_Build/ -lSapPackets
INCLUDEPATH += $$PWD/../SapPackets
DEPENDPATH += $$PWD/../SapPackets
#include <iostream>
#include "SapEntityClass.hpp"
using namespace Sap::Entity;
int main(int argc, char *argv[])
{
SapEntityClass obj(56,"Sample");
std::cerr<<obj.GetId();
return 0;
}
问题:我在Compilationa上遇到以下错误
main.obj:-1: error: LNK2019: unresolved external symbol "public: unsigned short
__thiscall Sap::Entity::SapEntityClass::GetId(void)const " (?
GetId@SapEntityClass@Entity@Sap@@QBEGXZ) referenced in function _main
请帮助我解决这个问题。
编辑:为什么您要在实现文件中内联该方法?内联函数及其声明必须具有可见的定义。GCC针对实现文件中的内联方法报告了相同的链接器错误,因此我认为这是您的问题-删除方法定义中的内联方法或将其移至标头。
旧答案:好吧,您只发布了带有Sap :: Entity :: SapEntityClass :: GetId()方法声明的标头。定义在哪里?看来它没有实现,或者至少没有链接到您的应用程序。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句