This tutorial mainly explains the use of Fortran to generate DLLs for Qt calls (Win64)
The software and documentation required for this tutorial can be downloaded from the following connection:
Http://pan.baidu.com/s/1c04jziC
Fortran I use the software is Codeblocks, this is a Gfortran-based open source software.
1, first of all, said Codebolcks environment configuration:
First download codeblocks (hereinafter referred to as CB), this has nothing to say, download just.
1.1, Codebolcks of Chinese:
Place the downloaded. Mo file under: CODEBLOCKS\SHARE\CODEBLOCKS\LOCALE\ZH_CN
Open CB: Settings, environment settings, view, tick Internationalization->chinese
Restart CB on the line
1.2. Compiler settings (only for 64-bit systems):
If your system is 64-bit, you want to generate a 64-bit DLL.
First download tdm-gcc-64 compressed package, unzip. My decompression is on the F-drive.
Set-up compiler->toolchain executables->
Compiler installation directory changed to F:\TDM-GCC-64
C compiler, C + + compiler, dynamic linker, static linker, resource Compiler
are changed to F:\TDM-GCC-64\bin.
Such as:
2. Generate the DLL with Codebolcks:
FILE--New project->fortran->fortran DLL, take a name I fetch DLL
This should automatically generate a main.f95 file, directly dot yellow gear compiled on the line.
Then find the folder you built the project, in the \bin\debug folder should have these three files, we only need the DLL file
3. dll generated with QT dynamic link codeblocks:
Open Qt, create a new project, execute Qmake, will automatically generate a folder, mine is build-untitled-desktop_qt_5_4_2_msvc2013_opengl_64bit-debug
Copy the previously generated Dll.dll to the build-untitled-desktop_qt_5_4_2_msvc2013_opengl_64bit-debug\debug folder under
Enter the following code in MAIN.CPP:
#include <QCoreApplication> #include <QDebug> #include <qlibrary>typedef void (*fun) ();// Define the type of the exported function (this function type is to be consistent with the DLL) int main (int argc, char *argv[]) { qcoreapplication A (argc, argv); Qlibrary dll ("Dll.dll");//Load DLL if (Dll.load ()) {Fun sub= ("Dll.resolve"),////////////////////DLL/// if (sub) { qdebug () << "Success!"; } else{ qdebug () << "load function failed!"; } } else{ qdebug () << "Load DLL failed!"; } return a.exec ();}
Compile display "Success! "The docking is achieved.
4, the DLL call mode:
4.1, about the VC + + DLL Call:
dynamic-link library (DLL) dynamic invocation and static call, static link library (passive lib) call, this blog post is very clear:
Http://www.cnblogs.com/chio/archive/2007/11/03/948480.html
4.2, about the QT DLL call mode:
The display invocation (dynamic invocation) of the QT DLL and the implicit invocation (static invocation), this blog post is very clear:
Http://www.cnblogs.com/hicjiajia/archive/2010/08/27/1810239.html
4.3. qt creation and invocation of Dll/static Lib:
When QT creates DLLs, it is added in. Pro:
TEMPLATE = Lib
(1) DLL display call:
I wrote this article is to use the qlibrary display call , the advantage is that only the. DLL file can be called, do not need to add the Lib path in. Pro
(2) DLL implicit invocation:
Static calls often require . h files, add LIB + = "absolute path \ filename. dll"in. Pro (note the direction of the slash)
Declare the header file #include file name in. cpp . h
When QT creates the static lib, it is added in. Pro:
TEMPLATE = Lib
CONFIG + = Staticlib
(3) Static link library:
If it is a static library, you will also need a . lib/.a file, and declare it in . Pro first. lib/.a
Includepath + = "absolute path"
Lib + = "absolute path \ filename. lib" or "lib + =" absolute path \ filename. a "
Declare the header file #include file name in. cpp . h
Note:
Qt can also use qpluginloader, this please self-brain, also need. h and other files
Adding LIBS in Qt can also be done by adding a library to the. Pro right-click and selecting the Path
5. View of the function name in the generated DLL:
Download depends open DLL to see the function name
Open the previous DLL, you can see the function name Sub_
6, about makefile and programming principle:
I believe a lot of people are like me . lib/.a,. dll/.so,. OBJ/.O The relationship between these files will be very confused, read the following article is almost understand:
Http://wenku.baidu.com/link?url=FY5aNAyRmb73cWAaivKZuYY7coJhUm7kDBpQgzpM2X-hoXLPYqo89G_ Rhhztk2uaqp7a03ekww4di2b_zdashcsfxf4d9-f4tzelmelwwlc
And here are some generalizations about makefile usage:
Http://wenku.baidu.com/link?url=ErxBlB_bWtPNhoNLIUpLepIbTuP0oU8tWcKlyxt0e92mep1HqCZkfD_ Lhsyjupyxzh76carkz-hbgfum5xr_inoh4v6a9hmfwtuw7i8lhio
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Win64 Qt and Fortran (codeblocks) Mixed programming