PDA

View Full Version : Use external DLL ?



pl01
10th November 2010, 11:48
Hi,

I have a project that I build with QTCreator 2.1 beta. I have a PureLight.DLL file for the first project where I declare my methods like this


__attribute__((dllexport)) int plGetError();

In another application, I would like to use this DLL, and so I use the following code:


__attribute__((dllimport)) int plGetError();

But when I build my application it gives me this error message :

undefined reference to '_imp_plGetError'

What does it mean, do you have an idea ?

Thanks

high_flyer
10th November 2010, 12:33
Did you include the header file that defines plGerError()?

pl01
10th November 2010, 13:31
Of course, it sounds that it is a "link" error and not a "compilation" error

squidge
10th November 2010, 13:54
Indeed it does, did you link with the appropriate .lib file?

pl01
10th November 2010, 14:23
I need a ".lib" file to link to a DLL ? Is it really necessary ?

It is a DLL... so it should discover methods at run time ?

high_flyer
10th November 2010, 14:48
Your DLL knows about its symbols, but the outer world does not, the lib file has information about the symbols inside the DLL.
You don't actually need the lib, but its much more complected to do with out a lib file.
You can use delayed dll loading and than use GetProcAddress() and manually based on the header create the pointers to the function in the DLL.
You might need that if you don't have a lib file to an external DLL - but you do have the header (you need to know the constructs of the functions - an export file can also be used). or if you wish not to distribute your lib file for what ever reason.
Based on your questions, you should probably first practice in building and using DLLs the "normal" way - and read about what linking is and how it works.
Some useful links:
http://msdn.microsoft.com/en-us/library/ms686944%28v=VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/151kt790.aspx