Compile Fortran static library & dynamic library, and demonstrate the linking to a third-party Fortran library in C++/Fortran project. [中文]
Platform | Code | Project | Compilers | Build tools | |
Linux | C++ | Fortran External Library | GNU Fortran | GNU make | |
C++ Project | GCC | ||||
Fortran | Fortran External Library | GNU Fortran | Intel Fortran | ||
Fortran Project | GNU Fortran | Intel Fortran | |||
Windows | C++ | Fortran External Library | Intel Fortran | Visual Studio | |
C++ Project | Intel C++ | ||||
Fortran | Fortran External Library | Intel Fortran | |||
Fortran Project | Intel Fortran |
- Source code repository: Fortran_External_Library
open lib.sln
or dll.sln
with visual studio (>2010 sp1) which is located in .\{language}_{Type_of_library}\{Type_of_library}\msvs\
:
Build - Batch Build - Select all - Build
then similar operations with public_code.sln
which is located in .\{language}_{Type_of_library}\public_solution\msvs\
the binary file is located in .\public_solution\binary\
git clone https://github.com/nescirem/Fortran_External_Library.git
cd Fortran_External_Library
chmod -R 711 ./
For the cases of Fortran link to Fortran external library, Intel Fortran and GNU Fortran is supported:
./fortran_dynamic_library/build.sh
./fortran_static_library/build.sh
For the cases of C++ link to Fortran external library, only GNU Fortran with g++ is supported:
./cpp_static_library/build.sh
./cpp_dynamic_library/build.sh
or you can specify compiler and debug mode like this:
./fortran_dynamic_library/build.sh ifort release
./fortran_static_library/build.sh gfortran debug
./cpp_static_library/build.sh debug
./cpp_dynamic_library/build.sh release
Remember to clean:
./fortran_dynamic_library/clean_all.sh
./fortran_static_library/clean_all.sh
./cpp_static_library/clean_all.sh
./cpp_dynamic_library/clean_all.sh
Not recommended. If you want to use this PowerShell script, read help first:
.\test_all.ps1 -h
Currently Intel Fortran projects (.vfproj) do not support MSBuild. So this PowerShell script uses devenv.exe to open the *.sln file which includes Intel Fortran projects and wait for the user to build it manually.
Use python script to compile and test.
python test_all.py
- Linking third party Fortran dynamic library with C++ (linux)
- A more practical case
All codes are released under MIT license except make_depends_tree.sh
in ./tools
[pirpyn]: Fortran-Project-Template
[臭石头雪球]: http://v.fcode.cn/
[Neo Insight!]: https://www.avex.idv.tw/?p=243
[Calling Fortran from C/C++]: https://medium.com/@waltermateriais/calling-fortran-from-c-c-aa32867bde20
[Calling C++ (cpp objects) from a Fortran subroutine]: (https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/734563)
[C++ Calls in Fortran]: https://modelingguru.nasa.gov/docs/DOC-2642
[Using C/C++ and Fortran together]: http://www.yolinux.com/TUTORIALS/LinuxTutorialMixingFortranAndC.html
[C++ passes a string to a Fortran link library]: http://bbs.fcode.cn/thread-1117-1-1.html