I just wanted to let the list know I fixed the problem with linking my netcdf 4.0 library to a fortran program. Note, the macports netcdf install works fine with C code calling netcdf routines, only fortran code seemed to be an issue (even with the +g95 variant). The steps I took were the following:

build szlib as standard installation from macports
build openmpi with the +gcc43 variant so that fortran is enabled
build hdf5-18 with the +gcc43 variant, again so that fortran is enabled
build netcdf using gcc43 with fortran enabled - I wrote my own Portfile to do this as I wanted netcdf 4 capabilities. The macports netcdf installation does not activate netcdf-4 (in which case you might as well just install netcdf-3.x).

Then, when compiling code that references libnetcdf.a use

>> gfortran -fsecond-underscore -I/opt/local/include program.f -o program -L/opt/local/lib -lnetcdf

The -fsecond-underscore is critical, at least for my setup. Otherwise the code will not link to the netcdf library, which has second underscores. I suppose you could also build the netcdf library with FFLAG -fno-second-underscore. I did not try this. I'm curious why the gcc43 compiler suite built the netcdf library with second underscores but does not build my .f code with them.

my Portfile (used macports netcdf portfile as a template):

PortSystem 1.0
name            netcdf
version         4.0
maintainers     [email protected]
platforms       darwin
categories      science

description     NetCDF - Network Common Data Form
long_description        NetCDF is an interface \
for array-oriented data access and a library that \ provides an implementation of the interface. The \ netCDF library also defines a machine- independent \ format for representing scientific data. Together, \ the interface, library, and format support the \ creation, access, and sharing of scientific data. \ The netCDF software was developed at the Unidata \
                        Program Center in Boulder, Colorado.

homepage        http://unidata.ucar.edu/packages/netcdf/

master_sites    ftp://ftp.unidata.ucar.edu/pub/netcdf/ \
                http://www.gfd-dennou.org/arch/netcdf/unidata-mirror/ \
                ftp://www.gfd-dennou.org/arch/netcdf/unidata-mirror/
checksums       sha1 bea99846265e55e54be2c200ae004acc3a221c0a

depends_lib     port:hdf5 \
            port:szip

configure.cppflags      "-DNDEBUG -Df2cFortran"
configure.cxxflags      "-O2 -fno-common"
configure.cflags        "-O2 -fno-common"
configure.args  --disable-f77 \
#               --enable-shared \
                --enable-netcdf-4 \
                --with-zlib=${prefix}/lib \
                --with-szlib=${prefix}/lib \
                --with-hdf5=${prefix}/lib

test.run        yes
test.target     check

destroot.destdir        prefix=${destroot}${prefix} \
                        MANDIR=\\\${prefix}/share/man

post-destroot {
        file delete -force ${destroot}${prefix}/share/man/whatis.db
}

variant g95 {
        depends_lib             port:g95
        configure.args-delete   --disable-f77
        configure.fc            ${prefix}/bin/g95
        configure.env-append    FCFLAGS=-O2
}

variant gfortran43 {
        depends_lib             port:gcc43
        configure.args-delete   --disable-f77
        configure.cc            ${prefix}/bin/gcc-mp-4.3
        configure.cxx           ${prefix}/bin/g++-mp-4.3
        configure.fc            ${prefix}/bin/gfortran-mp-4.3
}




On Mar 16, 2009, at 12:15 PM, Yolande Serra wrote:

I've written previously about this issue and got no reply. I'm trying again after trying everything I could think of to get my netcdf 4.0 library installed with macport to work with the gcc43 also installed with macport. I made a local port for netcdf in which I compiled it with gcc43 after having installed gcc43 from macport. The build worked and I configured it with gfortran so that the fortran libs were also installed with my netcdf libs. I selected to not have separate fortran libraries and did not configure with shared libraries so everything is in libnetcdf.a. I checked using otool and all the right references are in libnetcdf.a, at least if I compare it to a working version of netcdf 4.0 on my old powerpc mac. No netcdf 4.0 options were turned on so I did not have to install netcdf with hdf5, zlib or szlib (as this is what I tried at first and did not get it to work).

So, the question is why do I get linking errors when I try to compile fortran code that calls the netcdf libs? I compile the code with gfortran-mp-4.3 and use the same options as when I built netcdf 4.0 (-fno-second-underscore -O2 -g). I also have provided the location of the include file and library explicitly in the compile command line (-I/opt/local/include and -L/opt/local/lib -lnetcdf). I also call some udunits functions which do not give any errors and udunits was also installed using macports and is in /opt/local.

Do I need to recompile the gcc43 using the same options (-fno-second- underscore)?? I tried compiling netcdf libs without this option, but this also did not work. I tried compiling my code without that option as well and it did not work. I also tried -fno-underscoring - no luck. I have a netcdf 4.0 library installed on my powerpc mac and can use gcc4.3 with that library with no problem but neither of these packages were installed with macports. I'd like to use macports for the new mac (intel), as it seems more convenient than building source code myself all the time. However, I desperately need a working netcdf library as all my data is stored this way.

Thanks for any help, Yolande


_______________________________________________
macports-users mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macports-users

_______________________________________________
macports-users mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macports-users

Reply via email to