0

I have the problem of linking the HDF-EOS library to a Fortran90 program. I have compiled the library from source to a directory specified in $prefix. My simple compile command is:

gfortran -I$prefix/include -L$prefix/lib -Wl,-rpath -Wl,$prefix/lib -lhdfeos -lGctp -lmfhdf -ldf -lz -lsz -ljpeg tst.f90

When compiling, I get the following error:

undefined reference to `gdopen_'

In the program, which I am not supposed to change, the HDF-EOS library is used via the external keyword, e.g.

integer(kind=4), external :: gdopen

In the library, nm $prefix/lib/libhdfeos.a | grep gdopen gives me:

00000000000120c0 T gdopen

When compiling with -fno-underscoring, I get just a different error:

gfortran -fno-underscoring -I$prefix/include -L$prefix/lib -Wl,-rpath -Wl,$prefix/lib -lhdfeos -lGctp -lmfhdf -ldf -lz -lsz -ljpeg tst.f90

the error is then:

undefined reference to `gdopen'

Also, gfortran finds the libraries, otherwise it would complain. Is the error related to the underscore? What else can I try? I work on Fedora and gfortran version 4.7.2.

1 Answer 1

1

Yes, very likely to be caused by the underscore.

Try compiling with -fno-underscoring (https://gcc.gnu.org/onlinedocs/gfortran/Code-Gen-Options.html), but fixing it by a proper bind(C) interface would be better.

This tutorial (Did you read it before going here? Very easy to find even for a complete novice in the library, like me.) also states you should use -fno-underscoring.

Continue by implementing the rest what the tutorial recommends, including compiling with FC=$(HDF4_DIR)/bin/h4fc.

Sign up to request clarification or add additional context in comments.

8 Comments

I should have mentioned that in the question, I tried it, but with no success, I will update my question accordingly.
@Andre BTW, "gfortran finds the libraries, otherwise it would complain" is completely false.
Yes I did, it didn't help me, then I moved on and eventually came here. Shouldn't gfortran complain if I use -lhdfeos and it is not able to find a libhdfeos.a file?
The linker should complain, but that is after the compilation by gfortran is finished. But you do not specify libhdfeos.a in your example, it could also be using a dynamic library.
Ok, I thought I was doing that by adding the -lhdfeos parameter.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.