how to get 2 trailing underscores?

Hi all.

I've just started using the sun fortran and c compilers.

My code uses the CDF (common data format) library for data output. I can compile the library (using gcc or suncc), but when I call it from fortran code it can't find symbols. The symbols' names in the library have 2 trailing underscores while fortran linker expects one or none depending on -ext_names=... option. How do I make it look for the right symbol names? Or how do I compile the library so that the names only have 1 trailing underscore? Or any other suggestions?

Thanks,

Victor.

[589 byte] By [fly_awaya] at [2007-11-27 1:24:06]
# 1

Is there a compiler based option in the makefile for the CDF library? The CDF makefile _should_ have an option for which c compiler you are using . If you look in the CDF code, you should see some preprocessor directives that name the C functions in different ways i.e. lowercase,uppercase, underscores depending on the value of a flag set in the makefile.

Brendana at 2007-7-12 0:14:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2

I am not aware of such an option for any of the 3 c compilers available - gcc, suncc, icc. What I have been doing so far is setting a fortran option to have 2 underscores

Intel Fortran: -assume 2underscore

gfortran: -ff2c

g95 automatically is compatible with gcc.

But with sunf95 and either gcc or suncc - I don't know what to do. And I don't see anything related to underscoring in the Makefile.

fly_awaya at 2007-7-12 0:14:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3
There is no way to get the Fortran compiler to append two underscores. I don't know why the library would be built with routines that have two trailing underscoes. Which CDF library are you using? As far as I recall, when I built netcdf 3.5.1 years ago it just worked.
igba at 2007-7-12 0:14:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4
I am using CDF 3.1. Not netCDF. http://cdf.gsfc.nasa.gov/I don't know why the library is built that way either.
fly_awaya at 2007-7-12 0:14:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 5

OK, I downloaded CDF from that site. It works for me with the following make command:

make OS=solaris ENV=x64 FORTRAN=yes SHARED=yes FC_solaris=f90 LD_solaris_x64="cc -xarch=amd64" all

(That assumes that "cc" and "f90" are on your path, and refer to the Sun compilers. It also assumes that you're building for a 64-bit AMD or Intel processor.)

The trailing underscores are controlled by some preprocessor defines in cdf31-dist/src/include/cdflib.h. I think it is set up to use two trailing underscores if the compiler defines the preprocessor macro "sun". Since our compiler does predefine that macro, I don't understand why I'm getting only one underscore. At any rate, you can change that file if that make command doesn't work for you.

igba at 2007-7-12 0:14:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 6
Are you building the library in Linux or Solaris? I am getting the same problem with these options too.
fly_awaya at 2007-7-12 0:14:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 7
I am using Solaris. Probably the easiest thing for you to do would be to edit cdflib.h.
igba at 2007-7-12 0:14:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 8

CDF library is an external library to my code. Changing its source code is not an option. Maybe the developers will provide a Makefile option for building it with Sun compilers as they did with Intel ones. Or maybe Sun will provide an option of adding 2 underscores.

Thanks for your help anyways. For now I am just gonna stick with the compilers that already work.

fly_awaya at 2007-7-12 0:14:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 9

If you don't want to wait for the day when

CDF sources are explicitly configured for Sun Linux

compilers, you could always try to impersonate another Linux compiler.

Without changing cdflib.h, for example, you could try to build with

"cc -D__ICC" to try to fool CDF into thinking the Sun compiler is the Intel compiler.

Of course that might not work but it may be worth a try.

Note that Sun compilers on Linux will predefine -Dlinux for you, and they

do not predefine -Dsun (mostly because there's too much software out there

that thinks that -Dsun means "Solaris").

mingrassa at 2007-7-12 0:14:45 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 10
This is a good one!!! I just set -Ulinux -Dsun and it compiled fine.Thanks a lot.
fly_awaya at 2007-7-12 0:14:46 > top of Java-index,Development Tools,Solaris and Linux Development Tools...