Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Undefined symbols for NETCDF 4.2 #13050

Closed
dongli opened this issue Jun 27, 2012 · 25 comments
Closed

Undefined symbols for NETCDF 4.2 #13050

dongli opened this issue Jun 27, 2012 · 25 comments

Comments

@dongli
Copy link
Contributor

dongli commented Jun 27, 2012

I used ifort to compile NETCDF:

export FC=ifort
brew install netcdf --enable-fortran

The compilation was successful, but when I built my codes, "ifort" complained:

Undefined symbols for architecture x86_64:
  "_netcdf_mp_nf90_strerror_", referenced from:
...

So I checked the symbols in /usr/local/lib/libnetcdff.5.dylib by nm, there is no _netcdf_mp_nf90_... symbols, but /usr/local/lib/libnetcdff.a has. What is wrong?

@2bits
Copy link
Contributor

2bits commented Jun 27, 2012

@Sharpie does this look like something he can easily adjust for his compiler choice, or are we suggesting people use gfortran if at all possible to build this?

@dongli can you give the us the simplest Fortran source code that will reproduce this?

@Sharpie
Copy link
Contributor

Sharpie commented Jun 27, 2012

This will be difficult to debug as I don't have access to ifort any longer, so I cannot test it. Generally, if you're not using our gfortran distribution to build things you may be on your own since we can't debug what we can't reproduce.

However, it would be very useful to see the output of brew instal -v netcdf --enable-fortran in a gist as I have a couple of guesses as to what may be going wrong but can't say for sure unless I see a build log.

@dongli
Copy link
Contributor Author

dongli commented Jun 28, 2012

@2bits Any Fortran code calling NETCDF can reproduce this:

program main

    use netcdf

    integer ncid, ierr

    ierr = nf90_open("test.nc", nf90_nowrite, ncid)

end program main

@Sharpie I can't copy the output in a gist, maybe it is too long?

When I linked with the static libs, it succeeded:

ifort -o test test.f90 /usr/local/lib/libnetcdf.a /usr/local/lib/libnetcdff.a -lcurl -lhdf5 -lhdf5_hl

@2bits
Copy link
Contributor

2bits commented Jun 28, 2012

I get an error when I try to compile that code. I named it test.f90 and ran

$ gfortran -o test test.f90 /usr/local/lib/libnetcdf.a /usr/local/lib/libnetcdff.a -lcurl -lhdf5 -lhdf5_hl
test.f90:3.14:

    use netcdf
             1
Fatal Error: Can't open module file 'netcdf.mod' for reading at (1): No such file or directory

@dongli
Copy link
Contributor Author

dongli commented Jun 28, 2012

@2bits You need to install netcdf, and please use ifort if possible, since I got no problem with gfortran. Thanks!

@2bits
Copy link
Contributor

2bits commented Jun 28, 2012

I did install netcdf with --enable-fortan and I don't have that file, netcdf.mod anywhere on my system. Not sure what the story is. I'll look around for ifort.

@jbeezley
Copy link
Contributor

I have a bit of experience with netcdf so I might be able to help.

@2bits: It seems to be creating NETCDF.mod rather than netcdf.mod. Try to add -I/usr/local/include. Strange that the compiler seems to be looking for it in lower case. I wonder if the gfortran modules are working on case sensitive file systems.

@dongli: I don't have access to ifort on mac, but I tried on Linux, and it seems fine. Can you gist nm /usr/local/lib/libnetcdff.5.dylib? The build log would also help. I have had problems pasting into github's gist form at times (usually because the output contains non-printable characters). You might try creating an empty gist, then cloning git repo it creates and adding the content from the commandline. I have had to resort to that before.

@Sharpie
Copy link
Contributor

Sharpie commented Jun 28, 2012

The reason I ask for the install output is that ifort and GCC/Clang (can't tell which you are using without a build log) could have different name mangling schemes. So, if the dynamic library was assembled by GCC/Clang instead of ifort, then there may be some extra underscoring going on.

If this guess is correct, you may need to pass some extra flags to ifort in order to correctly resolve symbols in the dynamic library.

@2bits
Copy link
Contributor

2bits commented Jun 28, 2012

@jbeezley thanks for the info. This worked:

gfortran -o test test.f90 -lnetcdf -lnetcdff -lcurl -lhdf5 -lhdf5_hl -I/usr/local/include

What I don't understand is what I'm looking for. The symbol the example uses, nf90_open exists in both dylibs. I assume the idea is that when it's built with ifort, that will be missing from the dylib. I will try to reproduce that.

But the OP said this was missing: _netcdf_mp_nf90_strerror_ I don't have that in either library. This is the closest thing that I have:

$ nm /usr/local/lib/libnetcdff.a | grep nf90_strerror
0000000000000066 T ___netcdf__nf90_strerror
0000000000047fd8 S ___netcdf__nf90_strerror.eh

$ nm /usr/local/lib/libnetcdff.dylib | grep nf90_strerror
000000000000ae70 T ___netcdf__nf90_strerror

Because netcdf always has two underscores following it, netcdf__, this sounds like the extra underscoring that @Sharpie mentioned. I certainly don't have any symbols in either library that have _mp_ in the middle of their names.

$ nm /usr/local/lib/libnetcdff.a | grep _mp_
00000000000004a4 T _nf__create_mp_
00000000000009b8 S _nf__create_mp_.eh
0000000000000591 T _nf__open_mp_
00000000000009e8 S _nf__open_mp_.eh
0000000000000672 T _nf_delete_mp_
0000000000000a18 S _nf_delete_mp_.eh
                 U _nf__create_mp_
                 U _nf__open_mp_

$ nm /usr/local/lib/libnetcdff.dylib | grep _mp_
0000000000001f84 T _nf__create_mp_
0000000000002071 T _nf__open_mp_
0000000000002152 T _nf_delete_mp_

@2bits
Copy link
Contributor

2bits commented Jun 28, 2012

It looks like I have to give them my name, address, and phone number to try Intel's iFort for 30 days. I think I'll pass.

@jbeezley
Copy link
Contributor

ifort and gfortran mangle names differently particularly with functions in modules. For ifort, it generally looks like mp. gfortran uses . There are also issues with how many underscores go after the name. The reason I asked for a gist of the symbol names in libnetcdff.dylib was to see what sort of convention was in this file and if the strerror function was missing entirely or just mangled differently.

In any case, I suspect this is probably an upstream issue. Splitting the fortran and c interfaces has been a difficult transition.

@dongli
Copy link
Contributor Author

dongli commented Jun 29, 2012

@jbeezley I have upload the output of nm /usr/local/lib/libnetcdff.5.dylib into https://gist.github.com/3016300.

It looks like that there is no F90 interface.

@Sharpie The compilation output of brew install -v netcdf --enable-fortran --default-fortran-flags into https://gist.github.com/3016337.

@jbeezley
Copy link
Contributor

None of the fortran 90 subroutines are being linked into the shared library. Here is the reason why:

ifort: command line warning #10006: ignoring unknown option '-force_load,../f90/.libs/libnetcdff90.a'

They need to fix this upstream with the proper flag for ifort.

@2bits
Copy link
Contributor

2bits commented Jun 29, 2012

Nice one. I wonder if make check would have found that. I reported it upstream via email. @dongli if you can determine what the valid flag is for iFort, please let us know, and I'll forward that to the netcdf developers.

@dongli
Copy link
Contributor Author

dongli commented Jun 29, 2012

@jbeezley There seems a similar issue http://www.unidata.ucar.edu/support/help/MailArchives/netcdf/msg10626.html, which is related to libtool. The libtool on my Mac Pro is Apple Inc. version cctools-822.

@dongli
Copy link
Contributor Author

dongli commented Jun 29, 2012

If the default gfortran could be version "4.7", I will not use ifort.

@2bits
Copy link
Contributor

2bits commented Jun 29, 2012

That issue you linked implies the problem is with libtool. If you have automake and libtool brewed, then you can try to run autoreconf like this:

  def install
    system 'autoreconf', '-ivf'
    ENV.fortran if fortran?

    common_args = %W[
      --disable-dependency-tracking
      --prefix=#{prefix}
      --enable-static
      --enable-shared
    ]

After each system 'make install' I added a system 'make check' and everything seems to work when I try it.

@dongli
Copy link
Contributor Author

dongli commented Jun 30, 2012

@2bits I have added system 'autoreconf', '-ivf' as you mentioned, but encountered the following errors:

==> Downloading http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-cxx4-4.2.tar.gz
Already downloaded: /Library/Caches/Homebrew/netcdf-cxx4-4.2.tar.gz
/usr/bin/tar xf /Library/Caches/Homebrew/netcdf-cxx4-4.2.tar.gz
==> ./configure --disable-dependency-tracking --prefix=/usr/local/Cellar/netcdf/4.2 --enable-static --enable-shared
./configure --disable-dependency-tracking --prefix=/usr/local/Cellar/netcdf/4.2 --enable-static --enable-shared
./configure: line 437: sed: command not found
./configure: line 548: sed: command not found
./configure: line 887: sed: command not found
./configure: line 913: sed: command not found
./configure: line 913: sed: command not found

@2bits
Copy link
Contributor

2bits commented Jun 30, 2012

Strange. Maybe each subformula needs autoreconf also. Gist the output of brew install -vd --enable-fortran netcdf. We'll be looking to see if it finds sed for the main configure stage. Consider adding two more autoreconf statements, one in each subformula:

    NetcdfCXX.new.brew do
      system 'autoreconf', '-ivf'
      system './configure', *common_args
      system 'make install'
      system 'make check'
    end unless no_cxx?

    NetcdfFortran.new.brew do
      system 'autoreconf', '-ivf'
      system './configure', *common_args
      system 'make install'
      system 'make check'
    end if fortran?

@dongli
Copy link
Contributor Author

dongli commented Jun 30, 2012

@2bits I added autoreconf in each subformula as you said, and the output is in https://gist.github.com/3016337.

==> Downloading http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-cxx4-4.2.tar.gz
Already downloaded: /Library/Caches/Homebrew/netcdf-cxx4-4.2.tar.gz
/usr/bin/tar xf /Library/Caches/Homebrew/netcdf-cxx4-4.2.tar.gz
==> autoreconf -ivf
autoreconf -ivf
Error: #<BuildError: Failed executing: autoreconf -ivf>

@2bits
Copy link
Contributor

2bits commented Jun 30, 2012

@dongli I just got that same error. You hit a bug in our formula. We set the PATH in the formula incorrectly. Below you can see how it has an extra space.

$ echo $PATH
/usr/local/Cellar/netcdf/4.2/bin /usr/local/bin:/usr/local/sbin:/usr/local/share/python:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/local/Library/Contributions/cmds

The space instead of a : is causing these problems. The bad code is this:

    ENV.prepend 'PATH', bin

Change that to be:

    ENV.prepend 'PATH', bin, ':'

Sharpie added a commit that referenced this issue Jun 30, 2012
@Sharpie
Copy link
Contributor

Sharpie commented Jun 30, 2012

Oops, that was my bad. Should be fixed now.

@2bits
Copy link
Contributor

2bits commented Jun 30, 2012

Thanks @Sharpie. It turns out that the netcdf website has a FAQ about iFort and MacOSX:
http://www.unidata.ucar.edu/software/netcdf/docs/known_problems.html#intel-fortran-macosx

They give us the fix too. We probably only have to check if FC == 'ifort' and if so, set
lt_cv_ld_force_load=no.

@dongli
Copy link
Contributor Author

dongli commented Jul 1, 2012

@2bits It works now!

@dongli dongli closed this as completed Jul 1, 2012
@2bits
Copy link
Contributor

2bits commented Jul 1, 2012

Great news. We'll add the lt_cv_ld_force_load=no to the netcdf formula if FC is set to ifort.

2bits pushed a commit to 2bits/homebrew that referenced this issue Jul 3, 2012
Netcdf when built with `--enable-fortran` using the Intel Fortran
compiler, ifort, does accept the `--force-load` option, causing a
build error where libnetcdff.dylib is missing all the f90 symbols.
The solution is in a FAQ on their website:
  Set lt_cv_ld_force_load=no

http://www.unidata.ucar.edu/software/netcdf/docs/known_problems.html#intel-fortran-macosx

Reported in Homebrew#13050
@Sharpie Sharpie reopened this Jul 3, 2012
@Sharpie Sharpie closed this as completed in d242bc6 Jul 3, 2012
mroderick pushed a commit to mroderick/homebrew that referenced this issue Jul 5, 2012
Netcdf when built with `--enable-fortran` using the Intel Fortran
compiler, ifort, does accept the `--force-load` option, causing a
build error where libnetcdff.dylib is missing all the f90 symbols.
The solution is in a FAQ on their website:
  Set lt_cv_ld_force_load=no

http://www.unidata.ucar.edu/software/netcdf/docs/known_problems.html#intel-fortran-macosx

Fixes Homebrew#13050.
Closes Homebrew#13174.

Signed-off-by: Charlie Sharpsteen <source@sharpsteen.net>
eproxus pushed a commit to eproxus/homebrew that referenced this issue Jul 18, 2012
eproxus pushed a commit to eproxus/homebrew that referenced this issue Jul 18, 2012
Netcdf when built with `--enable-fortran` using the Intel Fortran
compiler, ifort, does accept the `--force-load` option, causing a
build error where libnetcdff.dylib is missing all the f90 symbols.
The solution is in a FAQ on their website:
  Set lt_cv_ld_force_load=no

http://www.unidata.ucar.edu/software/netcdf/docs/known_problems.html#intel-fortran-macosx

Fixes Homebrew#13050.
Closes Homebrew#13174.

Signed-off-by: Charlie Sharpsteen <source@sharpsteen.net>
Sharpie added a commit to Sharpie/homebrew that referenced this issue Sep 12, 2012
Sharpie pushed a commit to Sharpie/homebrew that referenced this issue Sep 12, 2012
Netcdf when built with `--enable-fortran` using the Intel Fortran
compiler, ifort, does accept the `--force-load` option, causing a
build error where libnetcdff.dylib is missing all the f90 symbols.
The solution is in a FAQ on their website:
  Set lt_cv_ld_force_load=no

http://www.unidata.ucar.edu/software/netcdf/docs/known_problems.html#intel-fortran-macosx

Fixes Homebrew#13050.
Closes Homebrew#13174.

Signed-off-by: Charlie Sharpsteen <source@sharpsteen.net>
snakeyroc3 pushed a commit to snakeyroc3/homebrew that referenced this issue Dec 17, 2012
snakeyroc3 pushed a commit to snakeyroc3/homebrew that referenced this issue Dec 17, 2012
Netcdf when built with `--enable-fortran` using the Intel Fortran
compiler, ifort, does accept the `--force-load` option, causing a
build error where libnetcdff.dylib is missing all the f90 symbols.
The solution is in a FAQ on their website:
  Set lt_cv_ld_force_load=no

http://www.unidata.ucar.edu/software/netcdf/docs/known_problems.html#intel-fortran-macosx

Fixes Homebrew#13050.
Closes Homebrew#13174.

Signed-off-by: Charlie Sharpsteen <source@sharpsteen.net>
@Homebrew Homebrew locked and limited conversation to collaborators Feb 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants