Other Fortran compilers have an option to generate a source code listing (typically with a .lst file extension) that shows source code, symbol cross reference, common blocks, etc. I cannot find any documentation on how to do this with gfortran. For example, on Linux:
Intel: ifort -list ...
IBM: xlf -qsource ...
PGI: pgf90 -Mlist ...
SUN: f95 -Xlist ...
Related
I am encountering issues when trying to compile fortran code using meson build system on an HPC cluster.
On the cluster, I am using Intel compiler suite. The meson compile command aborts at the linking step with:
ld: /usr/bin/../lib64/crt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
ninja: build stopped: subcommand failed.
The interesting thing is that the link command issued by meson is something like this:
icpc -o main main.p/somefile.o ..., so it is using Intel's C++ compiler to link my fortran code. I tried to use the exact same command line, replacing icpc with ifort and adding -lstdc++. That actually worked.
So, I wonder, is there a way to force Meson to link my code with ifort, instead of icpc? Or, should I do something else?
I am afrad I cannot share the code at this moment. But, I'm open to showing bits and pieces of the meson.build file(s), if needed.
Details
The codebase consists of fortran source and a CMake C++ subproject; Essentially, the C++ subproject is a wrapper for OpenCV image plotting functions. This is why I needed to add -lstdc++ to my successful manual link command above.
Meson version: 0.55.3
Intel Fortran compiler: ifort (IFORT) 19.1.3.304 20200925
Intel C++ compiler: icpc (ICC) 19.1.3.304 20200925
The code is MPI parallelised.
The same code compiles well with GNU compilers v10 on a normal workstation.
Meson is not going to do any hand-holding when it comes to mixing languages. Here is what I found out works for Intel compilers:
fc=meson.get_compiler('fortran')
# cxx=meson.get_compiler('cpp')
...
if (fc.get_id() == 'intel')
#if (cxx.get_id() == 'intel')
...
add_global_link_arguments('-cxxlib',language : 'fortran')
add_global_link_arguments('-nofor_main', language : 'cpp')
endif
...
executable('myprog','myprog.f90', ..., link_language : 'fortran')
#executable('myprog','myprog.f90',...)
I am trying to migrate a .FOR file (for practice purposes) from ifort to gfortran. This file compiles in my Intel Visual Fortran solution with no issues. However when I compile it in gfortran using the following command:
gfortran -ffree-form -ffree-line-length-200 -Dinternal_debug -c MyFile.FOR -o MyFile.o
I get the following error message:
MyFile.FOR:4561:22:
102 format(A, I)
1
Error: Nonnegative width required in format string at (1)
Does ifort simply not require there to be a format width or are there additional ifort options that enable relaxing this requirement? How come the file runs smoothly in ifort but not in gfortran?
Your observation is correct, I have encountered this myself before. Intel Fortran does not enforce this requirement while gfortran does. The field width is actually required by the Fortran standard. I am not aware of any compiler option that could change this behaviour. The only option I am aware of is to fix the code to make it standard compliant.
How to do it can be found in Error: Nonnegative width required in format string at (1) . Note that the g0 that you asked about is not a compiler option to accept I. It is a different format descriptor to put into the code instead of I.
Does G++ compile without GCC or G++ is just translator // Including old g++ version.
when i was trying to install g++ from source i saw file
gcc.c
/* Default prefixes to attach to command names. */
#ifndef STANDARD_EXEC_PREFIX
#define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-"
#endif /* !defined STANDARD_EXEC_PREFIX */
//from g++1.4*
Well i know that c++ is c with classes i just wanted to know if the g++ can compile c++ without gcc .
With a recent GCC, gcc (actually cc1 which is run by gcc) and g++ (actually cc1plus) -and so on for other GCC compilers, e.g. gfortran or even gdc ....- share a lot of (source) code together: the middle-end (where most optimizations happen) and the back-end. The difference is only the front-end layer of the compiler (the only layer being source language specific) which is less than 30% of the compiler.
You could customize the GCC compiler with plugins or with MELT. Your extensions would work on GCC internal representations (Gimple-s) and would work when compiling C, C++, Ada, Fortran, etc... Remember that GCC means Gnu Compiler Collection today
Actually the gcc program is able to compile C++ source code (and likewise g++ can compile C or Fortran code). However, they are not linking the same libraries.
Pass the -v flag to the gcc or g++ command to understand what they are running.
Here are two (mine) [CC-BY-SA] pictures -explaing GCC & MELT- illustrating this.
The three layers -front-end, middle-end, back-end- of the compiler:
with your plugin, or the MELT meta-plugin
with a simplification: cc1 or cc1plus are generating assembler files, which is then translated by as started by gcc or g++
and
another view of the internals of cc1 or cc1plus,
which generates some assembler code
I am trying to run a code which compiles some c++ codes using mex.
I have set up mex with Microsoft Visual C++ 2010.
But when I execute the line
mex -O fconv.cc -o fconv
I get the error
compile
Usage:
MEX [option1 ... optionN] sourcefile1 [... sourcefileN]
[objectfile1 ... objectfileN] [libraryfile1 ... libraryfileN]
Use the -help option for more information, or consult the MATLAB API Guide.
C:\PROGRA~1\MATLAB\R2011A\BIN\MEX.PL: Error: Unrecognized switch: -o.
I have googled a lot but couldn't find anything of use. It would be great if you someone could help me out here. I have very limited knowledge of using mex.
From the R2013a docs for mex (and current version), there is no -o option, but there is -output:
-output resultname
Create binary MEX-file named resultname. Automatically appends the appropriate MEX-file extension. Overrides the default MEX-file naming mechanism.
BTW, the big O option (-O) is on by default unless you use -g.
Keep in mind that mex is not a compiler, but a frontend to the compiler. It has very different syntax from what you might be used to for a compiler.
Is it possible to convince GCC to emit an intermediate file which shows:
comments
original source
expanded macro definitions
optimizations applied by compiler
resulting C or C++ code which will be turned in to assembly code?
I'd rather see intermediate C/C++ instead of assembler, but I can use just assembler too if it's sufficiently annotated.
I am trying to reverse engineer a library composed almost entirely of macros in order to extend it. I'd also like to see the effects of optimization, in order to give the compiler more opportunities to do more optimization. (In other words, to see where my previous attempts have been ineffective)
GCC applies optimizations not in the C++-code directly but in some internal language-independant format (called GIMPLE) which cannot be reverted into C++ code that easily.
Depending on what you want, you can either
just expand macros: g++ -E
or look at an assembler output where you can see which line of C++ code maps to which assembler block:
g++ -g ... && objdump -S output
I don't recommend outputting assembler directly from gcc (with -S) as the generated annotations are almost useless.
1 and 2 are shown in, well, the original source.
3 You can get source with expanded macro definitions (in fact fully preprocessed) with -E.
4 The intermediate code at various stage of optimization can be obtained with -da or various -fdump-rtl-xxx, -fdump-tree-xxx and other -fdump-xxx options.
These are documented here:
http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Debugging-Options.html#Debugging-Options
5 I don't think GCC does source-to-source transformations, so the resulting C++ code is the original C++ code.
What transformations GCC does is described here:
http://gcc.gnu.org/onlinedocs/gccint/Passes.html#Passes