PDA

View Full Version : Problem with class-function from dll



Ragnar
15th July 2015, 10:39
Good Morning,

I created a .dll with Qt-creator 5.4, that is exporting some classes.
I now want to use these classes in an other Qt-Project. I managed to create an instance of the classes, but when i try to use a function (of course a public one) from one of the classes, i get an Error "undefined reference to ..."

Perhaps i make some very stupid errors, because its my first time working with a .dll

Can Anybody please help?

jefftee
15th July 2015, 19:50
Can you show the actual error and the relevant sections of the classes you are exporting?

d_stranz
15th July 2015, 23:25
"undefined reference to ..."

Are you linking to the .lib that gets created along with the .dll? Did you declare the classes you want to export with __declspec( dllexport ) when you built the DLL, and do you declare them with __declspec( dllimport ) when you want to use them in your EXE?

Ragnar
16th July 2015, 07:58
I am linking to the .a file that was created with the .dll, i found that it is the same as the .lib file when i searched google.
And i am using the Qt-Macro Q_DECL_EXPORT to export and the Qt-Macro Q_DECL_IMPORT to import (just because the Qt-Creator gave it to me when i made a library-project).
I can try to use __declspec( dllexport ) and __declspec( dllimport ), but i think it does the same as the Qt-Macros.

The code looks like this in my exported classes:


class Q_DECL_EXPORT test1
{
public:
test1();
int func1();
void func2();

}




EDIT: Thank you guys for your help, i solved the Problem now :)
There was a problem with the make-file i think, because i set a complet new project wit hexactly the same code and now it works, i can use the functions from the exported classes