PDA

View Full Version : Using A .DLL File?



steadi
28th October 2012, 15:41
Hello There,

I am trying to use a .dll file i created in my project. My question is: how would i go about doing this?

I have already tried Project >> Add Existing Files >> and then selecting the .dll
Then I used:
#include "MyDLL/mydll.h"

But this gives the undefined reference error.

Any help would be much appreciated. Thanks in advance,
Matt

ChrisW67
28th October 2012, 21:52
See the qmake manual for declaring other libraries and the LIBS variable.

steadi
28th October 2012, 22:09
See the qmake manual for declaring other libraries and the LIBS variable.
It appears to give me this error when i try to call a function from the .dll:

undefined reference to `_imp___ZN7SkyFallC1Ev'

Any ideas?

ChrisW67
28th October 2012, 22:19
The linker cannot find the library to link your application to. See the LIBS docs I pointed you at.

steadi
30th October 2012, 17:01
The linker cannot find the library to link your application to. See the LIBS docs I pointed you at.

Thanks man, the docs have really helped. However, i have decided to simply link the .h files to the project by using INCLUDEPATH and then linking it to the folder with the .h and .cpp files.

Even after doing this, however, i get the same goddamn error. Any ideas?

Thanks,
Matt

ChrisW67
30th October 2012, 23:06
You don't "link" a header file or link to a folder. You link compiled object files (e.g. main.o or floober.obj) and libraries (e.g. x.lib or libx.a) together to make the final executable. This magic is done by a thing called a linker. Qmake, when used correctly, sets all this up for you based on the rules you give it in the PRO file. The linker is given the object files that result from compiling all the SOURCES. It is also given the names of libraries (collections of object files) to link with through -l (lowercase-L) options in the LIBS variable. If the libraries are not in the standard locations then you can supply extra paths to be searched by giving -L options in LIBS.

Linking has nothing to do with includes or INCLUDEPATH: that is used in the preceding compilation stage.

If you have built a DLL project into folder /some/path/X then there will be project.dll and project.lib/libproject.a (exact names depend on compiler type) in that folder. To link your application object files with that library you use:


LIBS += -L/some/path -lproject


If you simply want to put some sources in a subfolder but build them directly into your project then you do that with:


HEADERS += subfolder/thingy.h subfolder/another.h
SOURCES += subfolder/thingy.cpp subfolder/another.cpp

The LIBS variable is not required because these files will be compiled into individual object files and linked automatically by the Makefile that qmake produces.