Linking an Executable to dln.dll

A dynamic-link library (DLL) is an executable file that acts as a shared library of functions.

There are two ways of linking: static and dynamic linking.

Dynamic linking provides a way for a process to call a function that is not part of its executable code. The executable code for the function is located in a DLL, which contains one or more functions that are compiled, linked, and stored separately from the processes that use them. DLLs also facilitate the sharing of data and resources. Multiple applications can simultaneously access the contents of a single copy of a DLL in memory.

Dynamic linking differs from static linking in that it allows an executable module (either a .dll or .exe file) to include only the information needed at run time to locate the executable code for a DLL function.

In static linking, the linker gets all of the referenced functions from the static link library and places it with your code into your executable.

Using dynamic linking instead of static linking offers several advantages. DLLs save memory, reduce swapping, save disk space, upgrade easier, provide after-market support, provide a mechanism to extend the MFC library classes, support multilanguage programs, and ease the creation of international versions.

We will review both methods of linking.

An executable file links to (or loads) a DLL in one of two ways:

  • Implicit linking (dynamic linking).

  • Explicit linking (static linking).

Implicit Linking

To implicitly link to a DLL, executables must obtain the following from the provider of the DLL:

  • A header file (.h file) containing the declarations of the exported functions and/or C++ classes. The classes, functions, and data should all have__declspec(dllimport).

  • An import library (.LIB files) to link with. (The linker creates the import library when the DLL is built.)

  • The actual DLL (.dll file).

Executables using the DLL must include the header file containing the exported functions (or C++ classes) in each source file that contains calls to the exported functions. From a coding perspective, the function calls to the exported functions are just like any other function call.

All required files for building your own application for DLN-series adapters can be found at '..\Program Files\Diolan\DLN\bin' (contains libraries) and 'Program Files\Diolan\DLN\common' (contains header files) after DLN setup package installation.

To build the calling executable file, you must link with the import library. If you are using an external makefile, specify the file name of the import library where you list other object (.obj) files or libraries that you are linking with.

The operating system must be able to locate the DLL file when it loads the calling executable.

You can connect dln.dll library in Visual Studio project by opening Property Pages Dialog, choosing Linker > Input and adding path string to dln.lib to Additional Dependencies field.

Property Pages dialog

Explicit Linking

With explicit linking, applications must make a function call to explicitly load the DLL at run time. To explicitly link to a DLL, an application must:

Call LoadLibrary (or a similar function) to load the DLL and obtain a module handle.

Call GetProcAddress to obtain a function pointer to each exported function that the application wants to call. Because applications are calling the DLL's functions through a pointer, the compiler does not generate external references, so there is no need to link with an import library.

Call FreeLibrary when done with the DLL.

Rating: 
Средняя: 1.5 (2 оценок)

Configure QT and QT Project with libdln.a for Linux

Configuring QT

To successfully create and compile QT applications and use libdln.a library in Linux, you need to correctly configure and setup QT. This steps should be performed after you successfully performed steps from Software & Hardware Installation in Linux page.

First, download QT sources from QT website (http://download.qt-project.org/official_releases/qt/4.8/4.8.5/qt-everywh...), unpack archive, open terminal in unpacked folder with QT, configure QT with-release and-static flags, then compile QT sources and install QT. For this example QT 4.8.5 version was used.

C/C++
./configure
-release -nomake demos -nomake examples
make
make install

Configuring QT Project and Connecting libdln.a Library

After QT is compiled you can compile and run any QT application by using properqmake project_name from application sources folder. You can use terminal or QT Creator for creating applications.

device_list_gui project compilation from terminal:

C/C++
path_to_qmake/qmake
device_list_gui
make

To use libdlb.a library in your application project, you need to add the following to project .pro file:

C/C++
QMAKE_LFLAGS
+= -static-libgcc
LIBS += /usr/local/lib/libdln.a # path to libdln.a library

Also do not forget to include required header .h files to your sources for successful usage API functions from libdln.a. For example:

C/C++
#include
"../common/dln.h"
#include "../common/dln_generic.h"

Rating: 
Голосов пока нет