Hello community
When I compiled the code using gfortran it generates all symbols in lowercase. in ifx/ifort there is a flag to change this behavior (-names uppercase). What is the best way to make this happen in gfortran? This is a problem when we are dealing in a mixed language projects.
If you have only a relatively few name conflicts, then you might consider using the bind()
clause. This allows you to define the external symbol however you want for that subprogram. To be useful, this should be done only for module subroutines which have automatic explicit interfaces, otherwise you will need to define also interface blocks wherever the routines are referenced.
Our code base is huge and manually making these changes are almost impossible. We maintain forks of LAPACK, BLAS and Sparse utility
There is no command-line option in (modern) GNU Fortran anymore, like g77 had it.
I have created a function in Makefile to capitalize symbols but the problem is it capitalize the library functions as well (eg: pow) and the linker will complain that it couldn’t find such symbols.
Define a function for capitalizing symbols
define capitalize_symbols
@nm $(1) | grep ’ [UT] ’ | while read -r line; do
symbol=$$(echo “$$line” | awk ‘{print $$NF}’);
if [ ! -z “$$symbol” ]; then
upper_symbol=$$(echo “$$symbol” | tr ‘[:lower:]’ ‘[:upper:]’);
objcopy --redefine-sym $$symbol=$$upper_symbol $(1);
fi
done
endef
This sort of rigid stuff make it so hard to compile for ARM64
I know Intel is not going to support ARM64.
How you could not quote the text at your link ? Below “GNU Fortran” refers to g77.
GNU Fortran offers the programmer way too much flexibility in deciding how source files are to be treated vis-a-vis uppercase and lowercase characters. There are 66 useful settings that affect case sensitivity, plus 10 settings that are nearly useless, with the remaining 116 settings being either redundant or useless.
nm --extern-only --defined-only
Finally I could solve this problem!!
An updated function to capitalize the symbols.
Compiler flags used -std=legacy -g -cpp -fPIC -Werror
# Define a function for capitalizing symbols
define capitalize_symbols
@echo "Processing file: $(1)"
@nm $(1) -j -g | while read -r symbol; do \
if echo "$$symbol" | grep -q '_$$' && [ ! -z "$$symbol" ]; then \
modified_symbol=$$(echo "$$symbol" | sed 's/_$$//' | tr '[:lower:]' '[:upper:]'); \
echo "Capitalizing and modifying $$symbol to $$modified_symbol"; \
objcopy --redefine-sym $$symbol=$$modified_symbol $(1); \
fi \
done
endef
You might consider going the other direction.
The gfortran compiler, like most Fortran compilers nowadays, follows the original AT&T Unix f77 compiler convention from the 1970s. That is, external names are lower case and have a single trailing underscore. (See: http://squoze.net/UNIX/v7/files/doc/21_f77.pdf)
There used to be a number of compilers with other conventions - some inherited from non-Unix systems that didn’t handle lower case well. But these seem to have largely fallen by the wayside. C pretty much forced the issue 30+ years ago.