Reputation: 1332
I have two module in Qt
1. SapPackets : lib
2. SapApplication : app
pro file for both module
SapPackets.pro has Qt -= gui
SapApplication.pro has Qt += core gui xml
Target OS is 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;
}
Problem: I am getting following error on 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
Please help me to resolve this....
Upvotes: 0
Views: 4556
Reputation: 1997
Edit:Why do you inline the method in the implementation file? Inlined functions must have visible definition together with their declaration. GCC reports same linker error for inlined method in implementation file, so I think that is your problem - remove inline in method definition or move it to the header.
Old answer: Well you posted only header with Sap::Entity::SapEntityClass::GetId() method declaration. Where is definition? It seems it is not implemented or at least not linked to your application.
Upvotes: 2
Reputation: 12600
This can happen when the linker finds the function definition, but not the implementation, which is most likely compiled into the library.
Try adding
LIBS += -lSapPacket
to your SapApplication.pro
file unless it's there already.
This tells your linker that there is a library called SapPacket.lib
(on Windows; file extension would be different on other OSs), which contains implementations of some functions.
Upvotes: 0