How to Include C/C++ Sources#
Abaci makes it easier to use C and C++ source files in combination with your Abaqus user subroutine code.
Given a user subroutine file usub.f
, we can easily compile and link a C or C++ source file
and call that from our user subroutine code.
Prerequisites: in order to compile C and C++ source files, you will need an appropriate compiler, either: Microsoft C/C++ compiler (Windows only), the Intel C Compiler or the GNU compiler suite (GCC).
Source Files#
Given a C++ source file lib_functions.cpp
in the src
folder, we
can tell Abaci about this by adding the following to our configuration file (abaci.toml
):
[compile]
sources = ['src/lib_functions.cpp']
Abaci will add a separate compilation step to compile any source files specified in this way.
When the main user subroutine file is subsequently compiled with abaqus make
, the compiled
C/C++ source files are linked in with this.
Hint
You can specify multiple C/C++ source files with globbing: sources=['src/*.c','src/*.cpp']
Compiler#
On Windows, C and C++ source files are compiled by default with the Microsoft C/C++ Optimizing Compiler (cl
).
On Linux, C and C++ source files are compiled by default with the Intel C compiler (icc
).
To use GCC for compiling C and C++ source files, on either Windows or Linux, add the --gcc
command line flag.
Example:
abaci run --gcc
Compiler Flags#
To customise the C/C++ compiler flags, you can specify cflags
in the configuration file:
Example:
[compile]
cflags.windows = ['/fp:fast']
cflags.linux = ['-fp-model' 'fast']
cflags.gcc = ['-funsafe-math-optimizations']