ujwala
5th May 2011, 11:38
Hi,
I am new to QT development. I have below query.
I am writing a simple dll in C++ which has a class with member function.
#DllProg.h
class __declspec(dllexport) Funcs
{
public:
Funcs();
void Print();
};
#DllProg
#include "DllProg.h"
#include <stdexcept>
#include <iostream>
#include <string>
using namespace std;
__declspec(dllexport) Funcs::Funcs()
{
cout<<"Funcs : In Constructor"<<endl;
}
__declspec(dllexport) void Funcs::Print()
{
cout<<"Print : In DLL";
}
extern "C" __declspec(dllexport) Funcs* getObject()
{
cout << "In getObject() "<<endl;
return new Funcs();
}
#QT Application
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
typedef Funcs* (*pf)();
QLibrary myLib("D:\\Practice\\QT\\QTClassApp-build-desktop\\debug\\DllProg.dll");
myLib.load();
if(myLib.isLoaded())
{
pf fptr = (pf)myLib.resolve("getObject");
Funcs *s = fptr();
printf("getObject Returned - %p" , s);
s->Print();
}
return a.exec();
}
Here I am getting Error on statement s->Print();
getObject() is properly getting called and returning instance of the class. But if I put call to Print its giving Linker Error - undefined reference to `Funcs::Print()'
#.pro
win32: LIBS += -L$$PWD/../QTClassApp-build-desktop/debug/ -lDllProg
INCLUDEPATH += $$PWD/../QTClassApp-build-desktop/debug
DEPENDPATH += $$PWD/../QTClassApp-build-desktop/debug
I found the ablove code on QT forum. I am not sure how correct is the code.
Thanks in Advance.
I am new to QT development. I have below query.
I am writing a simple dll in C++ which has a class with member function.
#DllProg.h
class __declspec(dllexport) Funcs
{
public:
Funcs();
void Print();
};
#DllProg
#include "DllProg.h"
#include <stdexcept>
#include <iostream>
#include <string>
using namespace std;
__declspec(dllexport) Funcs::Funcs()
{
cout<<"Funcs : In Constructor"<<endl;
}
__declspec(dllexport) void Funcs::Print()
{
cout<<"Print : In DLL";
}
extern "C" __declspec(dllexport) Funcs* getObject()
{
cout << "In getObject() "<<endl;
return new Funcs();
}
#QT Application
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
typedef Funcs* (*pf)();
QLibrary myLib("D:\\Practice\\QT\\QTClassApp-build-desktop\\debug\\DllProg.dll");
myLib.load();
if(myLib.isLoaded())
{
pf fptr = (pf)myLib.resolve("getObject");
Funcs *s = fptr();
printf("getObject Returned - %p" , s);
s->Print();
}
return a.exec();
}
Here I am getting Error on statement s->Print();
getObject() is properly getting called and returning instance of the class. But if I put call to Print its giving Linker Error - undefined reference to `Funcs::Print()'
#.pro
win32: LIBS += -L$$PWD/../QTClassApp-build-desktop/debug/ -lDllProg
INCLUDEPATH += $$PWD/../QTClassApp-build-desktop/debug
DEPENDPATH += $$PWD/../QTClassApp-build-desktop/debug
I found the ablove code on QT forum. I am not sure how correct is the code.
Thanks in Advance.